Storing feasible solutions in terms of original variables - scip

I want to store a feasible solution from an event handler that catches the SCIP_EVENTTYPE_BESTSOLFOUND event, and later I would like to give this solution as an heuristic solution to another SCIP instance that is optimizing the same problem but with different parameter settings (this could be in a subsequent optimization or in parallel).
My problem is that the solution I get from using SCIPgetBestSol() will be in terms of the transformed problem, which can be different from the transformed problem in the second SCIP instance.
Would turning presolve off (using SCIPsetPresolving()) be enough for ensuring that SCIP is always referring to the original variables within callback functions?
Is there a particular way that you would recomend for doing this?
Thanks!

Make sure that your event handler can access the array of original variables (SCIPget(N)OrigVars() does the trick). You can always query solution values of original variables, even from transformed solutions, using SCIPgetSolVal(), and store the values in a solution created via SCIPcreateOrigSol().
In order to feed this solution into a different SCIP instance, you have to get the mapping between variables of the primary and secondary SCIP instance right. Create a new solution for the secondary SCIP instance, and set the solution value of a variable to the value of its (pre-)image variable in the primary SCIP.

Related

force early exit in SCIP branch-and-bound

When using custom branching or node selection rules in SCIPopt, is it possible to force an immediate exit of the branch-and-bound search once a certain known solution is found? I want to say that a specific node is the solution that I want to take, and the B&B procedure should then exit immediately.
I looked at the callback return options for custom branching (https://www.scipopt.org/doc/html/BRANCH.php) and node selection. I don't see an obvious way to return an "exit now". Alternative ways I'm considering: globally fix all the variables or update the global lower bound to match my chosen solution.
Do you want to declare that solution to be optimal somehow? (or do you even know that it is?)
If that is not so important then you could simply callinterruptSolve. Other options would be to set, e.g., the gaplimit to what your gap currently is after finding that solution (using setRealParam)
Edit: So unless you can somehow prove to SCIP that your solution is indeed optimal all your possible options to do this will be somewhat hacky. At that point you might as well force the global lowerbound to match your found solution. Since I don't know how you know that your found solution is optimal I can't really help much more.

Nullable chained planning variable in Optaplanner

So I am looking at modelling an overconstrained routing problem, where not all tasks have to be picked up in that specific planning problem. Rather the objective will be to maximise the tasks picked up in that planning problem.
I was thinking this should be easy to achieve by allowing the planning variable to be nullable, but it seems that Optaplanner does not allow this on chained planning variables.
So the workaround I am thinking about would be to devise a Dummy/Ghost vehicle for which the objective be to rather minimise the tasks assigned to this vehicle. This approach seems to echo what has been said here.
Alternatively, I think I can put the value null in the valueRangeProvider but I am not sure if this would work as intended.
Is this a reasonable approach, or are there caveats using this approach ?
null in ValueRangeProvider doesn't work.
The Dummy workaround is very, very common - I did it a few times myself (including for the RH summit demo). But once PLANNER-226 is fixed, we can get rid of that dummy workaround.

Dict vs Record in elm

While implementing a simple app I ran into the problem of trying to update a nested record. I found a solution online but it really seems like a whole lot of bloated code.
As I was looking for alternatives I found Dictionaries. This seem like a solution to that problem -- If I use a dictionary inside of a record I can avoid all that bloated code and get nested updates.
Seeing dictionaries and records next to each other made me wonder, why would I use a record instead of a dictionary, or vice versa? The two seem really similar to me, so I am not sure I see the advantage of one or the other. Of course I can see that there is a difference in syntax, but is that all ?
I learned somewhere that the access time complexity of Dict is O(log(n)) -- does it do a binary search on the keys ? -- but I can't find the access time complexity for record, but I am wondering if that is O(1) and that is one of the advantages.
Either way, they both seem to map to 1 single data structure in other languages (e.g Python's dictionaries, JS objects, Java hash-tables), why do we need two in elm ?
Dicts and records might seem very similar when coming from JavaScript, but in a statically typed language they are actually very different. I think just about the only property they have in common is that they are both key-value containers.
The biggest differences, I think, are that Dicts are homogeneous, meaning values must be of the same type, and "dynamically" keyed and sized, meaning keys are not statically checked (ie. at compile-time) and that key-value pairs can be added at runtime. Records on the other hand includes the key names and value types in the record type, which means they can hold values of different types, but also can't have keys added or removed at runtime without changing the type itself.
The benefits of easily being able to insert and update a Dict is something you pay for when you try to get it back out. Dict.get returns a Maybe which you'll then have to handle, because the type doesn't give any guarantee that it contains anything at all. You also won't get a compiler error if you mistype the name of a key.
Overall, a Dict forsakes most of the benefits of static typing. I think a good rule of thumb is that if you know the key names, you should most likely go with records. If you don't, go with Dict.
You also seem about right regarding performance, but I think that's a secondary concern. Record access should be equivalent to accessing the elements of an array by index, since so much information is known at compile time that it can essentially be compiled down to a fixed-size array.

Are there any subtle differences between SeriesCollection.Add() and SeriesCollection.NewSeries()?

I am using vb.net to control an excel workbook.
I have noticed there are two options for creating a series in the series collection of a chart, either using SeriesCollection.Add() with some starting parameters specified as arguments, or using SeriesCollection.NewSeries() without initializing parameters.
I was wondering, besides the obvious difference that they are intialized differently, are there are any difference between the two that I should be aware of?
I am wondering because I have used SeriesCollection.Add() in the past, but now want to specify the x and y values more specifically than that method allows. This lead me to finding the SeriesCollection.NewSeries() method, however I am unsure if there are any important differences that are not obvious.
My purpose is to create a new series, and to assign the series to a variable of type excel.series for future manipulation. I really do not want to specify anything on start, but am not aware if this could cause other problems. thanks in advance!
The NewSeries command returns the new series. Even though Add states that it returns a series that it adds to the collection it does not. The documentation may be what is causing your confusion here. Check out this MSDN article on the subject: http://msdn.microsoft.com/en-us/library/ff194065.aspx

How to nest rules in HP Exstream?

I am using HP Exstream (formerly Dialogue from Exstream Software) version 5.0.x. It has a feature to define and save boolean expressions as "Rules".
It has been about 6 years since I used this, but does anybody know if you can define a rule in terms of another rule? There is a "VB-like" language in a popup window, so you are not forced to use the and/or, variable-relational expression form, but I don't have documentation handy. :-(
I would like to define a rule, "NotFoo", in terms of "Foo", instead of repeating the inverse of the whole thing. (Yes, that would be retarded, but that's probably what I will be forced to do, as in other examples of what I am maintaining.) Actually, nested rules would have many uses, if I can figure out how to do it.
I later found that what one needs to do in this case is create user defined "functions", which can reference each other (so long as you avoid indirect recursion). Then, use the functions to define the "rules" (and, don't even bother with "library" rules instead of "inline" rules, most of the time).
I'm late to the question but since you had to answer yourself there is a better way to handle it.
The issue with using functions and testing the result is that there's a good chance that you're going to be adding unnecessary processing because the engine will run through the function every time it's called. Not a big issue with a simple function but it can easily become a problem if the function is complex, especially if it's called in several places.
Depending on the timing of the function (you didn't say whether it was a run level, customer level, or specific to particular documents), it's often better to have the function set a User Boolean variable to store the result then in your library rules you can just check the value of the variable without having to run through the function every time.