Changing a parameter while branching in SCIP - scip

I use pyscipopt. I know how to add constraints while branching using handlers (kind of), but now I also want to change some parameters. I imagine that is similar, but couldn’t found an example.
What I want is as follows: -Every time a feasible node is found (or every 10 nodes for example) update a parameter.
How do I do this? Are there examples or documentation on this?

You should implement an event handler. Look in test_eventy.py for an example. The eventtype should be SCIP_EVENTTYPE_NODEBRANCHED. Then you can change parameters in the exec callback.

Related

How do I implement a PDDL generated plan into a Python code communicating with motors?

So i have a problem which I modeled using PDDL. I want to implement the plan generated from this problem to a an existing Python code which controls two motors via Wi-Fi with a loop on VS Code (Python). I want this code to take my plan and execute it. Does this mean I need to define the actions I have as functions for my Python code and read the .plan file as a text and call the functions step by step? What are other options I might have?
Thank you for sparing your time!
Yes, it means that for every action of your PDDL, you have a corresponding function. And for every object in your problem, you have a corresponding instance that you can pass as an argument to the functions.
When you get a plan, you must parse it, take the step of the plan and:
look up the function by your action name
look up the instances by name to pass them to the function.
Once the function completes successfully, repeat.
Note that if you want to be able to interrupt the action while it is ongoing, you might need more complex kind of functions, if not objects.

is there any way to prevent a view from being unbound on deactivation?

I find, even when assigning the decorator #singleton(false) to the view-model, that while the view-model does then persist as a singleton across activation/deactivation, the bindings and components, etc do not.
(I assume this is because they are stored in a container that is disposed on deactivation.)
The result is that upon every deactivation/activation of a view with a singleton view-model, the view is un-bound and then re-bound.
Is it possible to cause the bindings to persist across deactivation/activation?
This one stumped me for a good while. It also confused me as to why implementing it was not a higher priority for the Aurelia Team.
This takes a fair amount of code to get working. I have put the code in a Gist here: https://gist.github.com/Vaccano/1e862b9318f4f0a9a8e1176ff4fb727e
All the files are new ones except the last, which is a modification to your main.ts file. Also, all my code is in Typescript. If you are using Javascript you will have to translate it.
The basic idea behind it is that you cache the view and the view model. And your replace the router with a caching router. So when the user navigates back to your page, it checks first to see if there is a view/view model already created and uses that instead of making a new one.
NOTE: This is not "component" level code. That means I have tested that this works for the scenario that I use it for.
I got my start for making this change here: https://github.com/aurelia/router/issues/173 There is another user (Scapal) made something that works for him and posted it there. If what I am posting does not work for you, his may help you out.
i'm also interested in an answer to this.
maybe i'm now making a complete fool out of me but why not use aurelia-history navigate(..) command?

Cloning partially solved MIP and keeping current B&B tree

I would like to partially solve a MIP, clone the problem and have that copy of the problem continue optimization but with a different strategy (node selection rule, variable selection rule, etc), and keeping the current branch-and-bound tree. I know that this can't be done with either CPLEX or Gurobi, since they would start optimization from scratch in the copy.
Is there any way of doing this with SCIP?
I would really appreciate any help.
Best,
Rodolfo
If you don't insist on having a copy/clone, you always have the possibility to code your stopping criterion in terms of an event handler. I am sure you know our How to on adding event handlers.
There is also an event handler in the scip source code, the so-called soft time limit event handler src/scip/event_softtimelimit.c. There you can find sample code that changes the time limit after the first solution has been found. Parameters can be fed one by one by using the SCIPchg{Real,Bool,Int,Longint,Char,String}Param() methods in the code, or passed as a settings file, which might be easier if you want to change lots of parameters without adapting the code each time.
It is good practice to use settings files saved via the set diffsave command, which saves only the nondefault-settings. Otherwise, using a complete settings file, you might run into troubles because a time limit or memory limit gets changed without control.
A copy that includes data structures such as the tree used during the branch-and-bound solving process is currently not possible. The copy-mechanism of SCIP only allows to copy the problem as a whole and adjust the formulation by changing variable domains and/or objective coefficients.

Getting LP relaxation before SCIPsolve

I would like to use the LP relaxation of the problem before calling SCIPsolve() and I would like to know what is the best/simplest way of doing this.
I'm currently creating a SCIP_LPI that I would like to populate with my original problem's data. I thought that a simple way would be to call SCIPgetLPI() (and then copy everything), but when I write that problem to file (to see it) I get an empty problem. I guess this is because since I haven't called SCIPsolve() yet. I even tried calling SCIPpresolve() first, but the problem is still empty.
To get the LP relaxation I believe you will have to call SCIPsolve at some point. One way I see to do this and that does use SCIPsolve is to set the parameter limits/nodes to 1, call SCIPsolve, which will only solve the root node. Then you can set limits/nodes to -1 and call SCIPsolve again to solve completely if needed. Note that doing so will give you the LP relaxation of the presolved problem, and cuts will be added. Depending on what you would like to do, you may want to disable presolving and cuts.

What is the cleanest way to notify GUI to update in wxWidgets?

I have a small application that needs to update GUI elements if some event occurs in lower levels, say, socket goes off-line, or something like that.
In Windows, I could use PostMessage which would be sent through the chain to all Windows, and the required ones could update accordingly.
How can I achieve something similar in wxWidgets? I cannot use OnUpdateUI, or something like that, because some controls doesn't seem to handle that at all.
The target window could be one or multiple, they could be frames or controls, so I'm confused a little here.
Does anyone have a suggestion?
First, all controls do receive EVT_UPDATE_UI so you could use it for this and it's a very simple of doing it -- but also the most inefficient, so definitely not recommended for something like socket event processing (it's fine for checking whether the socket is connected or not though).
Second, the exact equivalent of Windows ::PostMessage() is wxQueueEvent() (which used to be called as wxPostEvent() actually but the new version is preferable). wxQueueEvent() is thread-safe in the sense that it can be used from a secondary thread to post an event to a GUI control managed by the main thread.
You can use the same approach as in Win32 apps. You can create the custom event class and send it to windows using wxPostEvent function. There are some docs regarding this.
Not sure what you mean about wxUpdateUIEvent - from my experience it works pretty fine. What controls do not receive it? Did you add EVT_UPDATE_UI() macro to event table?