# Questions tagged [linear-programming]

An optimization technique for minimizing or maximizing a function of several variables in the presence of constraints where all relationships are linear.

2,091
questions

**1**

vote

**1**answer

65 views

### Python PuLP Optimization Problem - Minimize Deviation from Average

I am trying to do an Optimization problem with PuLP but I am having an issue with writing my objective function.
I've simplified my real-life example to a simpler one using cereal. So let's say I have ...

**1**

vote

**0**answers

53 views

### Meal Plan Optimization Violating Constraints (Python, OR-Tools, Linear Programming, XLRD) [closed]

I've made a program to create meal plans that fulfill the recommended nutritional intake. I've gotten it to run, but it's giving results that violate the constraints, and I'm not sure why. How would I ...

**0**

votes

**0**answers

18 views

### Why is Microsoft Solver Foundation not returning a solution?

I'm trying to solve my linear program with Microsoft Solver Foundation, but it doesn't return a solution. It doesn't give a clear message to what is wrong, so I'm not sure what is going on. I have ...

**0**

votes

**1**answer

67 views

### How do I model this linear programming problem in Python?

I have been tasked to program a Dantzig Selector using Python, but I was given no guidelines and do not have much experience in linear programming or data science. I cannot find the information I need ...

**0**

votes

**0**answers

34 views

### how to solve stochastic programming problem (Python)? [closed]

I have a "probability tree (scenario tree) in probabilistic multi-stage modeling" problem. The issue is as follows. I want to use Python to solve it. But I have no background in solving ...

**0**

votes

**1**answer

39 views

### Implement objective fuction such that element that will be maximised with specific patern (x1+x2)/5 +(x1+x2)/ 2 + (y1+y2)/4 so on

I have created a objective function using pulp but I am not able to implement the specific pattern
prob = LpProblem("Delivery_Problem",LpMaximize)
items_names = df_items['name'].tolist()
...

**0**

votes

**0**answers

11 views

### Theorem 1 from "A geometric way to build strong mixed-integer programming formulations"

I'd like to build Theorem 1 from Vielma and Huchette's paper A geometric way to build strong mixed-integer programming formulations:
For my coding example I will use the "SOS2" sets T = [{i,...

**0**

votes

**0**answers

15 views

### Plot Isoprofit lines feasible regions on line graph

I'm struggling to add Isoprofit lines (In orange) as in the image below. Looking for a clever way to add the 2x isoprofit lines with a filled in region in orange as the picture indicates below.
import ...

**1**

vote

**2**answers

28 views

### Fill in feasible region with Fill_between

I'm trying to fill in the maximum outward region as attached in the image. Below code will generate the line graph, however, I'm struggling to fill in the region as in the image.
import numpy as np
...

**-2**

votes

**1**answer

46 views

### How to write python code for polyhedron linear programming? [closed]

Write a python code that solves the following:
Let A ∈ Rmx2 and b ∈ Rm describe the polyhedron Q = { x ∈ R2 : Ax ≤ b}
Compute the center of the largest circle of Q.
In this task, we consider Euclidean ...

**0**

votes

**0**answers

16 views

### how can i add utility constraind to a linear optimisation problem

I am trying to optimize a maximization problem where i need to load items in 2 van suck that maximum utility is met. by utility i mean cartoon of weight and volume is most efficient
The other ...

**0**

votes

**0**answers

23 views

### Fatal Error while running lp solve function

I'm trying to find one vector x with 69195 coordinates such that
sum(x)=4040
sum(A*x) is minimum
With A a matrix fixed. I want to solve it like a problem of binary linear programation with the "...

**0**

votes

**1**answer

21 views

### Reformulate max function into linear program using constraints

I have the following objective function
minimize 1000 + 3*max(0, x-10)
How do I reformulate this into a linear program?

**0**

votes

**0**answers

15 views

### minimizing equilibrium simplex using linprog

Im interested in solving the following equation the equilibrium simplex for a physical problem I am currently working on. I found the linprog(method='simplex') to quite resemble my problem, hence, I ...

**0**

votes

**0**answers

21 views

### How to tell PULP_CBC_CMD to report the first feasible solution

I found a way to set the relative gap and max time for this pulp solver:
https://coin-or.github.io/pulp/technical/solvers.html
(see the section about pulp.apis.PULP_CBC_CMD)
However, the R version of ...

**1**

vote

**0**answers

17 views

### Use of the gap and first feasible options with Symphony or CBC in R

The linear programs I am trying to solve are often too demanding to wait for an optimal solution, so I am evaluating the use of the 'gap' and 'first feasible' options.
Please correct me if I am wrong: ...

**0**

votes

**0**answers

34 views

### SCIP/OR-Tools: Stop solver after certain objective value has been reached

I am using or-tools with a SCIP to solve some Mixed Integer Linear Program. In other solvers, I know there are options to stop the solver once a certain objective value has been reached, for example ...

**0**

votes

**1**answer

43 views

### Given 2d dimensions and values for each items. Find maximum value you can get by filling in items in n x n container

This sounds very similar to knapsack or bin packing problem but I do not know how to approach it. The items are given 2d dimensions (width and height) instead of weights.
Ex.
container: 10 x 10
...

**0**

votes

**0**answers

21 views

### What are the constraints for this linear programming problem?

A writer creates math problems for a website. She gets paid $5 per word problem and $2 per algebraic problem. On average, it takes her 4 minutes to create a word problem and 2 minutes to create an ...

**0**

votes

**1**answer

40 views

### Google OR-Tools: Solving an objective function containing max function of multiple variables

I'm aiming to optimize an objective function that includes a max function of multiple variables. Is this possible with OR-Tools given it seems to only have linear solvers and the max function is ...

**0**

votes

**0**answers

33 views

### There are hardware recomendation for running a solver for Linear Programing with pyomo and GLPK?

I'm creating a model with Pyomo for solving an optimization problem in networking. the solver we are using is GLPK. The idea is that we will have a server that solves a request with the optimization ...

**2**

votes

**2**answers

60 views

### How do I prevent multiple starts/stops of my selection?

I have CVXPY problem defined with a volume array, and a cost array to match each of volumes. The problem has 192 variables and 3 constraints which I have defined.
My goal is to minimize the cost in ...

**0**

votes

**1**answer

58 views

### PuLP : What am I wrong in Objective Function?

I created objective function and found the error in syntax of Excess below.
*Excess = (inv[m]+order[m]for m in material) - sum(produce[i]usage[i][m]for m in material for i in product)
The Excess cost =...

**1**

vote

**0**answers

30 views

### CVXPY problem takes a long time to find an optimal solution

I have CVXPY problem defined with a volume array, and a cost array to match each of volumes. The problem has 192 variables and 3 constraints which I have defined.
My goal is to minimize the cost in ...

**0**

votes

**0**answers

16 views

### SolverFoundation InteriorPointSolver gives wrong solution for very simple LP problem

Problem
I have a C# project where I need to solve linear programming (LP) problems. I use Microsoft.SolverFoundation.InteriorPointSolver https://docs.microsoft.com/en-us/previous-versions/visualstudio/...

**1**

vote

**1**answer

26 views

### create distance_matrix using python dictionaries

I'm working on a facility location problem model and i would like to create a dictionary containing this distance matrix,
distance_matrix
I want the keys to correspond to the combination between first ...

**1**

vote

**0**answers

45 views

### Linear Optimization in Math.net

Math.NET seems to have a significant amount of functions dedicated to non-linear optimization, which would seem to imply that it also has some faculty for performing linear optimization, but I've been ...

**0**

votes

**1**answer

69 views

### How to multiply variable matrix by coefficient matrix in Python, using Gurobi

I want to multiply both matrix's below and set as objective for my model:
m = gp.Model("matrix")
x = m.addMVar((9, 9), vtype=GRB.BINARY, name="x")
c = np.random.rand(9,9)
m....

**1**

vote

**0**answers

51 views

### Certificate of infeasibility in python's linprog

I have an infeasible linear program in linprog and I would like to get a certificate of infeasibility. Formally, my linear program is of the form
Ax <= b, x >= 0 and I want a vector v>=0 ...

**0**

votes

**0**answers

46 views

### CoinOR cbc not accepting options (pyomo)

I am using pyomo and cbc to solve a model. I have tried to pass options using the following:
opt = SolverFactory('cbc')
opt.options['seconds'] = 3
OR
results = opt.solve(model, options={"seconds&...

**-1**

votes

**1**answer

26 views

### How can this be linear, according to Pyomo?

while linearizing some constraints containing divisions, I founda formulation which works and is interpreted as linear by Pyomo, and I absolutely have no idea why:
mod.coupling_temp2[m]*sum(mod....

**1**

vote

**0**answers

56 views

### Python Pulp error with pyspark: Unsupported Operation Between Types

I have an optimization problem where for each customer I have an FTE column (number of full time employees) and a profit column. There is a constraint on the number of FTEs and I need to maximize ...

**1**

vote

**2**answers

52 views

### Find linear combination of vectors that is the best fit for a target vector

I am trying to find weights across a number of forecasts to give a result that is as close as possible (say, mean squared error) to a known target.
Here is a simplified example showing three different ...

**0**

votes

**0**answers

31 views

### How can I use the jsLPSolver library locally in a browser?

I would like to use the jsLPSolver library locally in a browser, not via Node.js, for running linear programming optimisations.
Following the 'Install' section of the README, I'm loading the solver.js ...

**0**

votes

**0**answers

58 views

### python mixed integer linear programming with matrix-type input

I need to solve a linear program (LP) with a mix of binary and continuous variables (MILP).
The data I use as constraints and objectives come from pandas data frame manipulations, so they are in ...

**0**

votes

**0**answers

26 views

### scipy.optimize constraints by each row

Let's say I have the following:
category=['A','A','A','B','B']
refweight=[0.8, 0.1, 0.05, 0.05, 0.2]
maxweight=[0.2, 0.1, 0.7, 0.1, 0.1]
problem is to find W in which that mimimizes the squared ...

**0**

votes

**0**answers

40 views

### Defining the object function of an unbalanced optimization problem with exclusive nodes

I'm trying to solve the following optimization problem using PULP: consider there are multiple boxes (e.g. ['b1', 'b2', 'b3'] and each box has different objects inside it (e.g. [o1, o2, o3]. Each box ...

**1**

vote

**2**answers

43 views

### Julia JuMP Constraint from Vector

I'm practicing with Julia but got stuck trying to make a constraint.
# Server Costs
> df_custos = DataFrame(C1=[2,4,3],C2=[1,2,1],C3=[3,3,2],C4=[6,2,3],)
# City num
> num_cidades=ncol(...

**0**

votes

**0**answers

37 views

### Linearization of division between variables in pyomo

I need to formulate a constraint where a decision variable (a real number) is divided by another decision variable (an integer). This is obviously non-linear and I need a linear formulation.

**-1**

votes

**1**answer

65 views

### ValueError in linear program with cvxopt (Rank(A) < p or Rank([G; A]) < n)

I try to solve the following linear program using the cvxopt package in python and wonder how to fix the stated ValueError. I guess it's a modeling mistake taking into consideration that I am a ...

**1**

vote

**1**answer

28 views

### How to use sum of absolute difference condition in python pulp?

I have been looking up similar posts regarding absolute value condition in linear programming, and trying the proposed solutions. However, I am still struggling to make my pulp setup work in python.
I ...

**0**

votes

**1**answer

47 views

### Linearization of IFF between a binary and an integer

I'm trying to find the mathematical linearization of this constraint:
p = 0 if and only if s = 0
Where p is binary and s is an integer >= 0 (thus it cannot be treated as a binary!!!)
Thanks in ...

**0**

votes

**0**answers

32 views

### Calculating point of intersection using MINVERSE/MMULT

I can't seem to figure out how to find the point of intersection between 2 equations. I figured trying the MINVERSE/MMULT function might be able to help but my understanding is those can only work for ...

**0**

votes

**0**answers

39 views

### Why does a solution of a pyomo lp model sometimes violate hard constraints?

I have a pyomo concrete lp model with several hard and soft constraints. When solving it with the IBM ILOG CPLEX solver sometimes some hard constraints are violated even though the solver says the ...

**0**

votes

**1**answer

85 views

### Linearization of if-then constraint

I'm trying to linearize a constraint of this form:
if a == b then c = 1
where a and b are positive integers and c is a binary variable.
I'm looking for a solution like this one https://math....

**0**

votes

**0**answers

45 views

### Check reduced cost of new column in column generation

I'm working on a decomposition model using column generation. When generate a new column, I'd like to check it's reduced cost using CPLEX function. I did read a post here, however the sign of the ...

**0**

votes

**1**answer

30 views

### What are the known(polynomial) approximation algorithms to get MIP(Mixed-Integer Programming) solutions from LP relaxation?

I want to control these approximation algorithms in time and solution quality with my own approximation algorithm for a problem of mine and the MIP solution itself.
So what are the known approximation ...

**0**

votes

**0**answers

26 views

### Alternative for staticLex in Cplex

I'm using Cplex12.8 in Eclipse and I've got the undefined error for method cplex.staticLex due to my version as far as I know. staticLex is used in cplex12.9 if I don't make mistake. so I'm going to ...

**0**

votes

**0**answers

38 views

### Make binary decision variable 1 when X == some value, otherwise 0 in cvxpy

I have a decision variable matrix D. I am able to obtain the max value of each column by using cp.max() and store in an another decision variable maxes. Now what I want is another decision variable ...

**3**

votes

**2**answers

94 views

### Set the amount of possible unique values for variables in ORTOOLS CP-SAT

Looking to set/limit the amount of unique variables generated by ortools cp-sat.
I currently have a list of 13 variables i.e. x1, x2, x3...
I want to be able to ensure that out of these 13 variables ...