linear-programming

How do I generate PuLP variables and constrains without using exec?

徘徊边缘 提交于 2021-02-07 04:00:49
问题 I have written the following Python Code using the PuLP Library for solving the Knapsack Problem using the Integer Programming formulation. I am using strings to generate the LpVariable commands and add the constraints and then executing them with eval. Is there a way to do this without using eval? from pulp import * #Knapsack problem items = input ('Enter the number of items :') items = int(items) #print('Enter %d items one by one') print ('Enter {0} items profit one by one'.format(items))

Pyomo can't locate GLPK solver

允我心安 提交于 2021-02-07 03:20:27
问题 I'm trying to use the GLPK solver with Pyomo. I have a working model that's been tested, but keep getting an error saying GLPK can't be found. WARNING: Could not locate the 'glpsol' executable, which is required for solver 'glpk' I've installed glpk sucessfully. I also added the directory to my path variable so the executed can be called globally. I tested this with glpsol --help from my command line, and see the help info printed. The below thread says it should be working, but alas, it is

Pyomo can't locate GLPK solver

梦想与她 提交于 2021-02-07 03:19:17
问题 I'm trying to use the GLPK solver with Pyomo. I have a working model that's been tested, but keep getting an error saying GLPK can't be found. WARNING: Could not locate the 'glpsol' executable, which is required for solver 'glpk' I've installed glpk sucessfully. I also added the directory to my path variable so the executed can be called globally. I tested this with glpsol --help from my command line, and see the help info printed. The below thread says it should be working, but alas, it is

L1-Norm minimization

匆匆过客 提交于 2021-01-29 07:46:16
问题 I am trying to minimize the following function using Linear programming. I am unable to include the image of my objective function. Click this Objective Function to view what I am trying to optimize. My question is there any library or function in python which can do this optimization for me or should I be writing the code? 回答1: import cvxpy as cp import numpy as np N=10 M=100 U = np.random.random((M,N)) m = np.random.random(M) t = cp.Variable(M) x = cp.Variable(N) prob = cp.Problem(cp

Pulp : What does lpDot() does, How to use it

人盡茶涼 提交于 2021-01-28 20:13:53
问题 I am trying to generate an equation via lpDot() , Such as PulpVar = [x1,x2] Constants = [5,6] then doing dot product as: model += lpDot(PulpVar, Constants) Form what I understand this should generate an equation as x1*5+x2*6 but I am getting lpAffineExpression as output and the lp file so generated is empty 回答1: lpDot() – given two lists of the form [a1, a2, …, an] and [ x1, x2, …, xn] will construct a linear epression to be used as a constraint or variable ref So, if you use with constants,

Make K different (cardinality) google OR-TOOLS

旧时模样 提交于 2021-01-28 11:06:15
问题 I'm wondering if there is a generalisation of solver.AllDifferent(x) in google or-tools that allows for the specification of how many different elements I allow. So if len(x) = 4, then AllDifferent(x) means that len(set(x)) = 4. But what if I just want to enforce "at least 2 different", so: len(set(x)) >=2 ? Is there a constraint that generalises AllDifferent to be able to set the cardinality of the solution variable ? 来源: https://stackoverflow.com/questions/48021694/make-k-different

How to feed LP files to the GLOP solver of or-tools?

醉酒当歌 提交于 2021-01-28 07:13:01
问题 I would like to use or-tools and the GLOP solver to solve linear programming problems. I already have another program that creates LP files which are, as far as I know, fairly standard for defining linear programs. Has anyone managed to pass those files directly to GLOP? What file format das GLOP understand and how do I pass them to GLOP? Example lp file: maximize 2x1 + 3x2 - x3 subject to x1 + x2 <= 1 x1 + x2 + x3 <= 0 x2 - 2x3 <= 2 bounds x1 free x2 free x3 free end Edit: I am looking for a

Installing GLPK (GNU Linear Programming Kit) on Windows

情到浓时终转凉″ 提交于 2021-01-28 04:02:18
问题 This could be an annoying question. But I was hoping someone could provide me with step by step instructions on how to get GLPK up and running on a Windows machine. I have Windows 7 64-bit. I have tried looking at some instructions on various websites but keep running into problems. I am not very versed in creating directories, working with binaries (e.g. what is a binary), etc.... Even running commands is a little foreign to me. To get an idea of what kind of detail I need in the

CBC - know “why” a program is infeasible

六眼飞鱼酱① 提交于 2021-01-28 03:42:11
问题 I use CBC to solve different integer linear programming problems. For some of them, the set of constraints is such that there is no solution. In this case, I get something like this: Problem is infeasible - 0.30 seconds Infeasible - objective value -6832.50000000 Is there any way CBC can tell me somehow "why" the problem is infeasible? For example, I would be happy to have a minimal set of constraints that are incompatible. 回答1: I'm pretty sure, this functionality is not implemented in CBC.

Python Pulp using with Matrices

你离开我真会死。 提交于 2020-12-29 02:53:11
问题 I am still very new to Python, after years and years of Matlab. I am trying to use Pulp to set up an integer linear program. Given an array of numbers: {P[i]:i=1...N} I want to maximize: sum( x_i P_i ) subject to the constraints A x <= b A_eq x = b_eq and with bounds (vector based bounds) LB <= x <= UB In pulp however, I don't see how to do vector declarations properly. I was using: RANGE = range(numpy.size(P)) x = pulp.LpVariable.dicts("x", LB_ind, UB_ind, "Integer") where I can only enter