Constraint solving with choco: Finding unique solutions for a variable - constraint-programming

I'm using Choco to solve a CSP. In the beginning, I create an array of variables v like this:
IntVar[] v = new IntVar[5];
After adding several constraints, I'll search for solutions and find multiple of them. However, I want only unique solutions for e.g. v[4]. So all solutions should have a different value in the v[4] variable.
How can I achieve this?

Related

Why isn't it printing the value of the key but instead searches for a variable with a name of the value?

I've tried so many variations. Too many to list, and have scoured the internet for answers, but I can't figure out what's going on.
you use an f String. Thus, {d["A"]} is evaluated before putting the string into eval resulting into eval("print(bruh)").
Try this:
d = {"A": "bruh"}
eval('print(d["A"])')

How to speed up search including special character alternatives and nested loops (Python/Django webapp)?

I have three loops nested in a python/django webapp backend. all_recommended_services has all the service info I need to go through. alternatives has the search criteria entered in the search bar, including all special character alternatives (for example: u is substituted with ú, ö with ő and so on...). Finally, the loop for value in alternative: goes through all search words individually split by empty space.
There are search keyword combinations which yield millions of alternatives, which totally kills the webapp. Is there an efficient way to speed this up? I tried to look into itertools.product to use cartesian, but it didn't really help me avoid more loops or speed up the process. Any help is much appreciated!
for service in all_recommended_services:
county_str = get_county_by_id(all_counties, service['county_id'])
for alternative in alternatives:
something_found = False
for value in alternative:
something_found = search_in_service(service, value, county_str)
if not something_found:
break
if something_found:
if not service in recommended_services:
recommended_services.append(service)
As you are searching, I will suggest this package named Django-haystack. It is easy to use and is highly customizable to fit your needs. Since you didn't include more detail, I can't provide a more detailed demo, but the documentation is comprehensive.

I need to figure out how to access data in a groovy map in a Jenkinsfile

I'm a Groovy/Java noobie, I spend most of my time in C and golang.
In groovy (specifically in Jenkins using a pipeline), having this map (from println(mymap)):
[data:[access-type:ObjectRead, access-uri:/path/to/something, id:some_id=:some_value, name:some_name, object-name:some_object_name, time-created:some_time, time-expires:some_other_time]]
I want to assign access_uri directly to an environment variable. I have tried several different things, i.e. object.data.access_uri, object['data']['access_uri'], object['data':['access_uri']]
Nothing seems to work. Just a simple groovy nested map question. I know all of the keys and types, so I don't need/want to recurse the map. This is a bit frustrating since in my mind myvar = object.data.access_uri or at least myvar = object['data']['access_id'] should work.
Try using object.getAt("data").getAt("access_uri")

Getting the result of an excel formula in python

I need to open a .xlsx-file (without writing to it) in python, to change some fields and get the output after the formulas in some fields were calculated; I only know the input fields, the output field and the name of the sheet.
To write some code: Here is how it would look like if I would have created the library
file = excel.open("some_file.xlsx")
sheet = file[sheet_name]
for k, v in input_fields.items():
sheet[k] = v
file.do_calculations()
print(sheet[output_field])
Is there an easy way to do this? Wich library should I use to get the result of the formulas after providing new values for some fields?
Is there a better way than using something like pyoo, maybe something that doesn't require another application (a python library is clearly better) to be installed?
I'll just thank you in advance.
I now came up with a (very ugly) solution.
I am now reading the xml within the xlsx-file, and I am now using eval and some regular expressions to find out wich fields are needed; and I have defined some functions to run the calculations.
It works, but it would be great if there were a better solution.
If the resulting library is ready, and I don't forget to do this; I'll add a link to the library (that'll be hosted on Github) to this answer to my own question.

Avoiding auto expansion of columns in RawSQL

Apologize for the multiple questions on this topic. I am trying to update a column based on other columns in a table and so far nothing seems to be working. I tried updateWhere and then rawSQL with update (Ambiguous Type Error When Using RawSql Update) but both have issues.
updateWhere does not allow other columns names (only values) so that's ruled out.
I tried rawSQL with an Update but it is automatically expanding all the entity names which breaks the update. If there is a way to stop it from expanding column names (not putting ?? does not solve that problem), that will work perfectly. For example if I do: Update table SET X = Y - ? [input values] , it creates UPDATE table.f1, table.f2, etc. SET X = Y - ? [input values]
This is one of those queries that I want to run in the background as an admin so I don't care for type safety. If there is a way to blindly execute a SQL string, that will work as well.
All I want to do is : SET X = (Y - Constant). Any suggestions will be greatly appreciated.
Thanks you!
I haven't tried myself, but from reading the module documentation, I think rawExecute is what you are looking for.
You might also what to file a bug report for persistent. I don't think rawSql is supposed to do column name expansion for anything but ??. At the least, it's an omission in the documentation even if it's the desired behavior.

Resources