How can I get the solution values of the subproblem variables when using the default benders decomposition implementation from scip? - c++

What the title says. How can I print the solution values of the subproblem variables when using the default implementation of the benders decomposition from scip.
For printing the variables I use the function SCIPprintSol(sub_scip, sol, pFile, false) together with SCIPgetBestSol(sub_scip) to get the best solution. I already tried SCIPprintBestSol(sub_scip, pFile, false) but that function gives no output at all.
Is there any function that can give me the output I want to have or do I use any of the functions not in the right way and therefore get no real output?

Related

Piecewise function with variable values at domain breakpoints

In our model we need a set of equations
model.y[k] = model.F(model.x[k]) (where k is in a proper Set)
with piecewise function F(x) defined on a fixed set of domain variable (breakpoints), but with unknown, variable (!), values at these breakpoints.
I implemented the case via SOSConstraint(..., sos=2) and it works (I tested by SCIP solver).
Now we want to try other implementations of pw-functions (LOG, BIGM_BIN, DCC, DLOG, etc.) mentioned in Pyomo pyomo.core.base.piecewise.Piecewise code. But it seems that this class requires fixed numerical values for F(x) at all breakpoints. If a function passed by f_rule argument to Piecewise constructor returns Pyomo expression with variable, then I get the following error:
ERROR: evaluating object as numeric value: ...
Can somebody give an advice or an a reference to some example of a "variable" piecewise-function ?
E.g., regarding "LOG" representation (from Vielma etc.) I see the code of _LOGPiecewise function in pyomo/core/base/piecewise.py module. And I do not see any reasons to forbidden to use variables as "y"-values of pw-expression being constructed ...
Updated
I've succeeded to modify pyomo.core.base.piecewise module to use variables as values of pw-function. Frankly speaking, these "modifications" were just commenting of some fragments in piecewise.py...
But, for my problem, I did not get any speed up in comparison with SOSConstraint (for SCIP solver !).
Can anybody give the benefit of experience: what pw-models were faster SOSConstraint or LOG, BIGM_BIN, DCC, DLOG for other problems ?

Validate function parameters based on given constraints

Before saying anything, please let me make it clear that this question is NOT language-specific but part of my work on an interpreter.
Let's say we have an enum of Value types. So a value can be:
SV, // stringValue
IV, // integerValue
AV, // arrayValue
etc, etc
then let's say we have a function F which takes one of the following combinations of arguments:
[
[SV],
[SV,IV],
[AV]
]
Now, the function is called, we calculate the values passed, and get their types. Let's say we get [XV,YV].
The question is:
What is the most efficient way to check if the passed values are allowed?
(The original interpreter is written in Nim, so one could say we could lookup the value array in the array of accepted value arrays like: accepted.contains(passed) - but this is not efficient)
P.S. ^ That's how I'm currently doing it, although I've explored the option of using bitmasks too. However, I cannot seem how it would help, since order plays an important part too.

Provide variables as input arguments to MATLAB system command for a C++ executable

I have an algorithm implemented in MATLAB. I want to replace different built-in operations with my own C++ implementations. I do not want to use MEX for its extra overhead. Is there any way to provide variables as input arguments to my C++ executable function using the "system" command. For example, for a multiplier implemented in C++, the following works.
result = system('multiplier.exe 10 50')
The result is 500. But the following does not work:
a = 10;
b = 50;
result = system('multiplier.exe a b');
The result is always 0 in this case.
I have tried to use setenv and getenv functions. But the result is still 0.
Any help??
As hinted by user4581301 in a comment, your code is taking a and b as the strings a and b literally, and not translating them as 10 and 50 as expected by you. You need to put the values of a and b after converting them to strings instead. i.e.
result = system(['multiplier.exe ', num2str(a), ' ', num2str(b)]);
Matlab is passing them as string.
Trying to write your values to a file and reading from those file inside the said program might be a work around. But if your inputs/outputs are long and you want them to have appropriate data type, than you might want to filter the input and output streams (stdin stdout) from matlab and cpp to get the appropriate behavior.

Matlab coder build error when trying to access structures

I have a nested structure with some fields labeled as L1, L2 etc. I try to access a substructure within the structure using the following code.
lfield = lfidcalc(le);
substruct = bmstruct.(lfield);
Since le changes its value in every iteration, lfield also changes its value from L1 to L9.
However, when I try to build this code to generate a C++ executable, I get the following error.
Non-constant expression or empty matrix. This expression must be
constant because its value determines the size or class of some
expression. In this context, the value of the string must be known.
Can anybody please try to help me sort out this problem?
I'm not sure exactly what's causing the error message you're seeing, but in any case MATLAB Coder does not support accessing the fields of a structure using dynamic field names.
Perhaps that is the direct cause of what you're seeing, perhaps not: but in either case you have a problem.
Not all correct matlab code can be converted to C/C++. Especially this kind of (very handy) code. Have you put '%#eml' on the second line of your function? It indicates that you will generate code. From matlab website: " We use the %#eml directive to turn on the MATLAB M-Lint code analyzer and check the function code for errors and recommend corrections."

Can I check whether a variable has deterministic value by C++ API

I noticed that Z3 can do allsmt from some paper. In my project, I have to search for deterministic variables in a SMT formula. By deterministic I mean the variable can only take one int value to make the formula satisfiable. Is there a c++/c API function which can do this task?
The best I can do so far is to call the solver.check() function many times for the negation of each variable I am interested in. Is there a faster way to do this by using the API?
Basically, I want to do allsmt and predicate abstraction/projection.
There is no specialized API for checking if all models of a given variable have to agree on the same value. You can implement more or less efficient algorithms on top of Z3 to solve this question.
Here is a possible algorithm:
Get a model M from Z3.
For the variables you are interested in assert: Not (And([(M.eval(x) == x) for x in Vars]))
Recheck satisfiability. If the new state is unsatisfiable, then the remaining variales in Vars must have the same value. Otherwise, remove variables from Vars that evaluate to a new value different from the old M.eval(x), and repeat (2) until Vars is either empty or the context is unsatisfiable.