How to solve the linear relaxation of a PySCIPOpt Model - linear-programming

Given a pyscipopt.Model, how to solve its linear relaxation in the shortest code possible?
The documentation is hard to navigate. There was a similar question before, but the answer does not apply here.

You need to iterate through all variables and change their types to CONTINUOUS:
for v in model.getVars():
m.chgVarType(v, 'CONTINUOUS')
Then you can solve the LP relaxation of the problem. Please note that your model should be a standard MIP and not contain any nonlinear or general constraints.

Related

Can Pyomo solve non-convex MIQCP (bilinear problems) using Gurobi?

I want to model an optimization problem that contains quite some bilinear terms. As such, I want to make use of the functionality of Gurobi 9.0 to solve bilinear problems. Clearly, I can use the GurobiPy API. However, I might want to compare other solvers (like BARON). So, I wonder whether it is possible to use Pyomo to formulate the problem and then solve it using Gurobi? Will there be any problems?
As far as I can tell, there should not be a problem. The same Gurobi solver will be used. Your problem will just be modelled in a somewhat different syntax (PYOMO) which is easily portable for solving with a wider range of solvers.
If still in doubt, I suggest you try a very simple problem with a bilinear term.
Note however that BARON requires a commercial license unlike Gurobi which offers free academic licenses.
Best of luck!

lpsolve how solution changes if exclude some contraints

I have a code with lpsolve package which quite standard way calculates minimal price for given constrains. That works ok.
My next task is to see if i exclude or change one constraint, how does prices change? It could be ok to have little bit higher price, but one constraint is excluded for example. Is there any way to calculate this sensitivity towards constraints? I understand that brutal way is to solve problem again with one constraint excluded, but it's too computationally expensive. Is there any algorithm or so?
I have seen something that one can calculate sensitivity towards coefficients in constraint. But maybe there is simple elegant way for this. Thanks!

C++: Solve underdetermined linear system with lapack

Let's put it simple: I have an under-determined linear system of equations
Ax = b
and I want to get one valid solution, no matter which one of the infinite solutions for the system. And I want to get it as efficiently as possible.
I have checked general LAPACK routines and it seems that they cannot handle the under-determined case. For example, dgesv(), whose documentation is found here, will return and integer larger than 1 in INFO if the factor U, from PLU factorization, is singular, and it will not solve the system if that is the case.
I have also checked some routines for Linear Least Squares problems (LLS) (documentation here), which does exactly solve my problem, just not as efficiently as I wished. If the LLS problems I provide is under-determined, the LLS routine will return the vector that minimizes
||Ax-b||
Which is a valid solution. However, it is calculated as the solution to an optimization problem, and I was wondering if there is a more efficient way of obtaining a valid solution for my under-determined problem.
A similar question was made here, but I believe that my question is more concrete than that: I am using LAPACK, and I want to solve an under-determined system of linear equations as efficiently as possible.
For an under-determined system of equations:
The correct approach is to use singular value decomposition (SVD). Lapack offers singular value decomposition in the form of dgesvd.
To perform the SVD you will have to homogenize your problem to turn it into a matrix problem of the form: My = 0. This is easy to do by introducing another degree of freedom (another variable). This will transform the vector x -> y and matrix A -> M. When performing the SVD on the matrix M, the smallest singular vector will be the solution to your under-determined least squares problem.
I would recommend using matlab or octave to experiment before wasting time coding anything up.

CPLEX how to get all the different optimal solutions with the same cost

I have a problem solved by Cplex that has at least two different optimal solutions with the same value.
How can I get all the different optimal solutions with the same value?
Update: it is a linear programming problem
You could as said at
https://www.ibm.com/developerworks/community/forums/html/topic?id=d8d12e36-3150-4e1c-a956-d707d17f274c&ps=25
use the solution pool or an artificial objective in order to enumerate solutions.

How fast is simplex method to solve tsp?

How fast is simplex method compared with brute-force or any other algorithm to solve a ts problem?
You can't model a TS problem with a "pure" LP problem (with continuous variables). You can use an integer-programming formulation, wich will use the simplex method at each node of a research tree (branch and bound or branch and cut method). It will work for small problems, but it is slow because the problem is hard: with one binary variable for each edge for instance, you need a lot of constraints to model the fact that the path is a cycle.
Brute-force is intractable (the problem is exponential), do not even try it unless you have a very small problem. Use the MIP formulation, even for small problems.
For big problems, you should use some kind of heuristic (I think simulated annealing give good results on this one), or a "smart" modelization of you problem (column generation for instance) if you want an exact solution.