linear-programming

Port MATLAB bounding ellipsoid code to Python

浪尽此生 提交于 2019-12-20 12:16:00
问题 MATLAB code exists to find the so-called "minimum volume enclosing ellipsoid" (e.g. here, also here). I'll paste the relevant part for convenience: function [A , c] = MinVolEllipse(P, tolerance) [d N] = size(P); Q = zeros(d+1,N); Q(1:d,:) = P(1:d,1:N); Q(d+1,:) = ones(1,N); count = 1; err = 1; u = (1/N) * ones(N,1); while err > tolerance, X = Q * diag(u) * Q'; M = diag(Q' * inv(X) * Q); [maximum j] = max(M); step_size = (maximum - d -1)/((d+1)*(maximum-1)); new_u = (1 - step_size)*u ; new_u(j

How to get lpsolveAPI to return all possible solutions?

♀尐吖头ヾ 提交于 2019-12-20 05:52:23
问题 I am using 'lpSolveAPI' to solve multiple binary linear programming problems in R. How do I get it too return ALL the variable combinations for a maximizing problem. Ive searched the documentation and can not find a command for this. Trying to switch from package 'lpSolve' as it inconsistently crashes R. Here's an example problem: library(lpSolveAPI) #matrix of constraints A <- matrix(rbind( c(1,1,0,0,0,0,0,0), c(1,0,0,0,1,0,0,0), c(0,0,1,0,0,1,0,0), c(0,0,1,0,0,0,1,0), c(0,0,1,0,0,0,0,1), c

What is wrong with this forall -statement in CPLEX?

柔情痞子 提交于 2019-12-19 11:58:09
问题 I am trying to answer here but err: forall(t in 0..4){ a[t]<=z[t]; -a[t]<=z[t]; x[t+1]==x[t]+v[t]; v[t+1]==v[t]+a[t]; } 回答1: The recursive equation enters into un-initialized interval hence index out of exeption. You can avoid this bug by tweaking: initialize not-needed valuations and assign them to zero. This creates some overhead but simplifies the logic, cannot think about any simpler way to do this. 来源: https://stackoverflow.com/questions/13291906/what-is-wrong-with-this-forall-statement

scipy.optimize.linprog unable to find a feasible starting point despite a feasible answer clearly exists

痴心易碎 提交于 2019-12-19 03:15:25
问题 the vector k seems to satisfy all constraints. Is there something I'm missing here? Thanks. import numpy as np from scipy.optimize import linprog A_ub=[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

Linear Programming (Simplex LP) PuLP?

寵の児 提交于 2019-12-18 17:28:08
问题 In Python only, and using data from a Pandas dataframe, how can I use PuLP to solve linear programming problems the same way I can in Excel? How much budget should be allocated to each Channel under the New Budget column so we maximize the total number of estimated successes? I'm really looking for a concrete example using data from a dataframe and not really high-level advice. Problem Data Setup Channel 30-day Cost Trials Success Cost Min Cost Max New Budget 0 Channel1 1765.21 9865 812 882

Get constraints in matrix format from gurobipy

冷暖自知 提交于 2019-12-18 11:44:34
问题 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? 回答1: 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

How to convert quadratic to linear program?

醉酒当歌 提交于 2019-12-18 02:46:40
问题 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 + .

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

痞子三分冷 提交于 2019-12-17 19:49:13
问题 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 5 years ago . 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

How to fix constraints for allocation optimisation in PuLP python

末鹿安然 提交于 2019-12-14 03:12:53
问题 Background: I am trying to allocate customers Ci to financial advisers Pj. Each customer has a policy value xi. I'm assuming that the number of customers (n) allocated to each adviser is the same, and that the same customer cannot be assigned to multiple advisers. Therefore each partner will have an allocation of policy values like so: P1=[x1,x2,x3] , P2=[x4,x5,x6], P3=[x7,x8,x9] I am trying to find the optimal allocation to minimise dispersion in fund value between the advisers. I am

Linear Programs using R

本秂侑毒 提交于 2019-12-14 02:29:06
问题 How can we solve a linear program using R? I want to solve the following example: min -a -2b +4c Constraints a + b + s1 = 5 a + 3c -s2 = 10 2b - 3c = 20 a >= 0, b >= 0, c >= 0, s1 >= 0, s2 >= 0 The equations might not make total sense. I just need to know the syntax of writing these equations in R. I might write something like this for the above equations require(lpSolve) R.obj <- c(-1,-2,4) R.con <- matrix(c(1,1,1,1,3,-1,2,-3),nrow=3,byrow=TRUE) R.dir <- c("=","=","=") R.rhs <- c(5,10,20) lp