linear-programming

Get constraints in matrix format from gurobipy

♀尐吖头ヾ 提交于 2019-11-30 04:02:58
I coded my model in gurobipy and I want to get the matrix of constraints and vector of cost. Is there any way to access those? From the python API, there's no single function to get the matrix coefficients from a Gurobi model, but it's not to hard to write one yourself. It is convenient to have lists of your variables and constraints. If you have a gurobi model in variable m dvars = m.getVars() constrs = m.getConstrs() will give you the list of variables and constraints. You can then use m.getAttr to retrieve attributes related to the variables. To obtain the objective function coefficients,

if condition in ampl

你说的曾经没有我的故事 提交于 2019-11-29 18:00:28
I am new in ampl and I want to use if condition in ampl with the following information: I have a binary variable X[p,r], where {p in P, r in R}. Now I want to make a new constraint such that the variable R[p,r] is used where X[p,r]=0. I do not know how I can write it or even if the ampl can handle it or not, I tried the following constraint but they did not work: s.t. a1{r in R, p in P and X[p,r]=0}: s.t. a2{r in R p in P and X[p,r]=0}; s.t. a2{r in R ,p in P, and X[p,r]=0}; s.t. a2{r in R, p in P: and X[p,r]=0}; You cannot include a decision variable in the "for all" part of the constraint

Pyomo: Access Solution From Python Code

折月煮酒 提交于 2019-11-29 15:52:29
问题 I have a linear integer programme I want to solve. I installed solver glpk (thanks to this answer) and pyomo. I wrote code like this: from pyomo.environ import * from pyomo.opt import SolverFactory a = 370 b = 420 c = 2 model = ConcreteModel() model.x = Var([1,2], domain=NonNegativeIntegers) model.Objective = Objective(expr = a * model.x[1] + b * model.x[2], sense=minimize) model.Constraint1 = Constraint(expr = model.x[1] + model.x[2] == c) # ... more constraints opt = SolverFactory('glpk')

Minimum exact cover of grid with squares; extra cuts

妖精的绣舞 提交于 2019-11-29 10:50:09
问题 This problem appeared in a challenge, but since it is now closed it should be OK to ask about it. The problem (not this question itself, this is just background information) can be visually described like this, borrowing their own image: I chose to solve it optimally. That's probably (for the decision variant) an NP-complete problem (it's certainly in NP, and it smells like an exact cover, though I haven't proven that a general exact cover problem can be reduced to it), but that's fine, it

error: iostream.h due to including cplex

。_饼干妹妹 提交于 2019-11-29 07:40:21
I am trying to use cplex in eclipse in Ubuntu 12.04 but when I include ilocplex.h I get the following error /opt/ibm/ILOG/CPLEX_Studio124/concert/include/ilconcert/ilosys.h:360:22: fatal error: iostream.h: No such file or directory The only two includes are written as follows: #include <ilcplex/ilocplex.h> #include <iostream> I would appreciate if anyone could help me with this. David Nehme At the time ILOG's Concert library was first released, the older iostream.h headers were still common in C++ compilers, but it supports the standard iostream libraries. To use the standard headers and

Is there a simple algorithm for calculating the maximum inscribed circle into a convex polygon? [closed]

好久不见. 提交于 2019-11-29 02:35:38
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I found some solutions, but they're too messy. 回答1: Yes. The Chebyshev center, x*, of a set C is the center of the largest ball that lies inside C. [Boyd, p. 416] When C is a convex set, then this problem is a convex optimization problem. Better yet, when C is a polyhedron, then

How to convert quadratic to linear program?

陌路散爱 提交于 2019-11-28 23:44:31
I have an optimization problem that has in the objective function 2 multiplied variables, making the model quadratic. I am currently using zimpl, to parse the model, and glpk to solve it. As they don't support quadratic programming, I would need to convert this to an MILP. . The first variable is real, in range [0, 1], the second one is real, from range 0 to inf. This one could without a problem be integer. The critical part in the objective function looks like this: max ... + var1 * var2 + ... I had similar problems in the constraints, but they were easily solvable. How could I solve this

linear programming in python?

允我心安 提交于 2019-11-28 16:13:33
I need to make a linear programming model. Here are the inequalities I'm using (for example): 6x + 4y <= 24 x + 2y <= 6 -x + y <= 1 y <= 2 I need to find the area described by these inequalities, and shade it in a graph, as well as keep track of the vertices of the bounding lines of this area, and draw the bounding line in a different color. See the graph below for an example of what I'm looking for. . I'm using Python 3.2, numpy, and matplotlib. Are there better modules for linear programming in Python? Ali UPDATE: The answer has become somewhat outdated in the past 4 years, here is an update

if condition in ampl

断了今生、忘了曾经 提交于 2019-11-28 11:39:54
问题 I am new in ampl and I want to use if condition in ampl with the following information: I have a binary variable X[p,r], where {p in P, r in R}. Now I want to make a new constraint such that the variable R[p,r] is used where X[p,r]=0. I do not know how I can write it or even if the ampl can handle it or not, I tried the following constraint but they did not work: s.t. a1{r in R, p in P and X[p,r]=0}: s.t. a2{r in R p in P and X[p,r]=0}; s.t. a2{r in R ,p in P, and X[p,r]=0}; s.t. a2{r in R, p

Recommended library for linear programming in .Net? [closed]

左心房为你撑大大i 提交于 2019-11-28 11:07:55
Can anyone recommend a library - free, or commercial but affordable ( There are some listed here: http://en.wikipedia.org/wiki/Linear_programming#Solvers_and_scripting_.28programming.29_languages ....but I am just starting out with LP and hope someone can recommend something. I am trying to basically minimize pricing for cell phone subscription services. I guess the 1st question is : is linear programming even applicable to solving this problem? A simplified example: Base Plan Options Plan A: 200 Voice minutes, 10 Text Messages, 10 MB Data = $25 Plan B: 400 Voice minutes, 25 Text Messages, 25