linear-programming

Pulp add constraint that at least one LpAffineExpression is equal to one

↘锁芯ラ 提交于 2019-12-25 00:13:35
问题 Say I have a PuLP model defined as thus: model = pulp.LpProblem('',pulp.LpMaximize) And I have added an objective function (it does not matter) Now I have a list of LpAffineExpression objects: lps = [l1, l2, l3, ...] I want to add to the model the constraint that one of these LpAffineExpression evaluates to 1. How would I do so? Essentially what I'm looking for is the syntactically correct way to do the following: model += (l1 == 1 OR l2 == 1 OR l3 == 1 OR ...) Note that I do not know how

Is there an easier way to avoid this kind of index key error of pyomo?

筅森魡賤 提交于 2019-12-24 21:14:02
问题 I am working on a LP model with pyomo,but when I create constraint, it shows a key error of 'can not find a certain combination'. I know list all the combinations can solve this problem. But the real data has many combinations. Is there any easy way to deal with this knid of problem? thanks!Here is a simple example: from pyomo.environ import * import pandas as pd data = [['tom','A', 10], ['nick','A', 15], ['juli','B',14]] df = pd.DataFrame(data, columns = ['Name','Type', 'Age']) #set A = set

how to count the number of distinct items in a linear programming problem

核能气质少年 提交于 2019-12-24 18:51:44
问题 I am studying some linear programming problems with all-binary variables, where it is necessary to count (and then either constrain or maximise/minimise) the number of distinct items in the solution. This is the post I could find that seemed closest to it: https://stats.stackexchange.com/questions/136608/constrained-assignment-problem-linear-programming-genetic-algorithm-etc The 'items' being counted in this case are the supply centers used. I am trying to understand if the approach suggested

trying to read quadratic program in cplex, get error

ⅰ亾dé卋堺 提交于 2019-12-24 14:53:09
问题 I am trying to load a CPLEX LP file in to CPLEX using the "read" command. I believe that in this problem, I have a set of constraints that are quadratic. But, from what I understand CPLEX will still attempt to solve quadratic programming problems. However, when I try to read it in, I get this error: CPLEX Error 1437: Line 284: Illegal quadratic constraint sense. Is there something special I need to do to read in a quadratic programming problem? NOTE: I am able to load this LP file in to scip

Memory optimization while using CPLEX library in Java

本秂侑毒 提交于 2019-12-24 14:24:39
问题 I am using IBM CPLEX library for an optimization problem in Java. Since main memory was not enough for the application I found a property of CPLEX : "Memory emphasis: letting the optimizer use disk for storage". Default value for Memory Emphasis is 0. How can I change this property in Java? for (int i = 0; i < GreenOverlayGlobals.numNodes; i++) { for (int j = 0; j < GreenOverlayGlobals.numNodes; j++) { IloLinearNumExpr expr2 = cplex.linearNumExpr(); for (int p = 0; p < GreenOverlayGlobals

linear goal programming in R unable to find solutions

空扰寡人 提交于 2019-12-24 06:33:31
问题 I have the following linear goal programming problem that I'm trying to solve using R : I tried formulating using R in the following matrix format: Below is the reproducible example: library("lpSolve") a <- matrix(c(1,2,5, 1/2,1,3, 1/5,1/3,1),nrow=3,byrow=T) f.obj <- c(rep(1,6),rep(0,3)) f.cons <- matrix(c(c(1,-1,0,0,0,0,1,-1,0, 0,0,1,-1,0,0,1,0,-1, 0,0,0,0,1,-1,0,1,-1, 1,0,0,0,0,0,0,0,0, 0,1,0,0,0,0,0,0,0, 0,0,1,0,0,0,0,0,0, 0,0,0,1,0,0,0,0,0, 0,0,0,0,1,0,0,0,0, 0,0,0,0,0,1,0,0,0, 0,0,0,0,0

Which linear programming package should I use for high numbers of constraints and “warm starts” [closed]

旧巷老猫 提交于 2019-12-24 02:14:51
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I have a "continuous" linear programming problem that involves maximizing a linear function over a curved convex space. In typical LP problems, the convex space is a polytope, but in this case the convex space is piecewise curved -- that is, it has faces, edges, and vertices, but the edges aren't straight and

Gurobi, How to change a continuous variable to a binary variable

半腔热情 提交于 2019-12-24 00:52:29
问题 I am using gurobi-python interface. Is there anyway to convert a continuous variable to a binary variable. I just do not want to convert m.addVar(lb=0, ub=1, vtype=GRB.CONTINUOUS) to m.addVar(lb=0, ub=1, vtype=GRB.BINARY). I have to do it in another way, not using m.addVar() I appreciate your possible feedback. Thank you. 回答1: In the gurobi python API, you can simply set the vtype attribute on the variable. It is easy if you save a reference to the variable In your case, if you create a

The integer linear programming(ILP) function in CVXOPT returns non integers

旧时模样 提交于 2019-12-23 03:33:02
问题 I wanted to optimize a function using ILP implementing by CVXOPT , GLPK in python. I wrote this code, but it gives me non integer solution especially 0.5. Could anyone help me? import math import numpy as np import cvxopt from cvxopt import glpk from cvxopt import matrix G = np.array([ [-1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., -1., 0., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., -1., 0., 1., -1

Using min/max operator in integer programming

大城市里の小女人 提交于 2019-12-23 02:52:24
问题 I am trying to optimize an objective function using integer programming, I have to use Max operator in my function, I want to know is there any way to deal with that? Actually my question is similar to Using min/max within an Integer Linear Program but is different in some aspects: All variables are binary. Note that x4 and x5 are presented in two place. One possible solution is using auxiliary variables like the answer of similar question, but I am confused when using this solution for my