Is there a way to modify a Gurobi parameter (MIPFOCUS) in a Pyomo environment? - optimization

I'm relatively new in Pyomo and Gurobi. I'm trying to solve a Non-Convex quadratic programming but the solver output give me the following issue:
"gurobipy.GurobiError: Quadratic equality constraints are non-convex. Set NonConvex parameter to 2 to solve model."
So, I'm trying to modify the solver parameter in order to obtain the correct result.
p.s. I'm already tryed to install gurobipy but the package manager Pip give me: "Could not find a version that satisfies the requirement gurobipy (from versions: )
No matching distribution found for gurobipy"
Tanks a lot for your time and consideration!

This page explains how to set parameters in Pyomo: https://pyomo.readthedocs.io/en/stable/working_models.html#sending-options-to-the-solver
optimizer.options["NonConvex"] = 2
or
results = optimizer.solve(instance, options="NonConvex=2")

Related

How can I get test_value in PyMC(PyMC4)?

I am a newbie in Bayesian and Probabilistic inference, and sorry for this basic question. Recently I am following some examples in Bayesian Methods. And, the examples require me to use "tag.test_value." However, I am trying to use PyMC rather than PyMC3, so there is an error using the sentence. Although I tried to use others such as init_value, initial_value, it does not work...
Could you kindly let me know alternatives for that sentence to check the initial value in PyMC (that was originally test value in PyMC3)?
a = pm.Uniform("b", 0, 50)
print(a.tag.test_value)
AttributeError: 'ValidatingScratchpad' object has no attribute 'test_value
It appears that Aesara does not compute test value by default. You need to set aesara.config.compute_test_value = "warn". Then you can call a.get_test_value(). Hope this helps!

How to write if condition in gurobi 9.5?

Any example for using if statement in gurobi 9.5 ?
its my first time to use gurobi. I am trying to implement the following code via if statement however i keep getting error or infeasible model.
m.addConstrs(p2g[t]==0 for t in range(A) if pv_generation[t]<=load[t] pfor t in range(A) )
m.addConstrs(p2g[t]==p2g[t] for t in range(A) if pv_generation[t]>load[t] for t in range(A))
I've checked the gurobi documentation but it doesn't provide any clear example

Octave: quadprog index issue?

I am trying to run several files of code for an assignment. I am trying to solve an optimization problem using the "quadprog" function from the "optim" package.
quadprog is supposed to solve the optimization problem in a certain format and takes inputs H,f, A,b, Aeq, Beq, lb, ub.
The issue I am having involves my f which is a column vector of constants. To clarify, f looks like c*[1,1,1,1,1,1] where c is a constant. Quadprog seems to run my code just fine for certain values of c, but gives me the error:
error: index (_,49): but object has size 2x2
error: called from
quadprog at line 351 column 32
for other values of c. So, for example, 1/3 works, but 1/2 doesn't. Does anyone have any experience with this?
Sorry for not providing a working example. My code runs over several files and I seem to only be having problems with a specific value set that is very big. Thanks!
You should try the qp native Octave function.
You mention f is: c*[1,1,1,1,1,1] but, if c is a scalar, that is not a column vector. It seems very odd that a scalar value might produce a dimensions error...

Tensorflow: how to get the current variable scope as a python string (hopefully without creating a variable)

It is not mentioned in the documentation:
https://www.tensorflow.org/programmers_guide/variable_scope
Does anyone know how?
Thanks!
If you want to print out the current variable_scope and you are operating in tensorflow r 1.1.0:
print(tf.get_variable_scope().name)

Returning multiple solutions with CPLEX, 'bad suffix .npool'

I've tried generating multiple solutions with cplex using
option solver cplexamp;
option cplex_options 'poolstub=solfile populate=1 poolintensity=4';
...
for {k in K_mach_RESOURCES} {
solve SUB1[k];
for {l in 1..SUB1[k].npool}{
solution ("solfile" & l & ".sol");
display _varname, _var;
}
Gives the error
Bad suffix .npool for SUB1
context: for {l in >>> 1..SUB1[k].npool} <<< {
Possible suffix values for SUB1.suffix:
astatus exitcode message relax
result sstatus stage
The weird thing is that it's generating .sol files, but I don't know how to access the generated solutions! Possibly relevant info: there's multiple problems declared in the run file. Accessing Current.npool doesn't work either (in fact, it assumes Current is the latest DECLARED problem, not the latest SOLVED problem). Any ideas??
It seems as if the problem arose because the problem wasn't defined to be an INTEGER problem, but a LP-relaxation of an integer problem.
For some reason, CPLEX doesn't seem to support the populate method for linear programs.
I think you forgot the "solve" command
ampl: solve;
and then you can display the results.