linear-programming

gurobi - Error code = 10004 Unable to retrieve attribute 'X'

巧了我就是萌 提交于 2019-12-01 03:03:50
问题 I am getting an error in my c++/gurobi file: Error code = 10004 Unable to retrieve attribute 'X' I read that this might have something to do with labels? But I don't see how there is a problem. It works for some input files, but not for others. So I have created a toy file, t5.txt in attachment. This file does not work, but removing the last column and setting 8 to 7 fixes it. I am puzzled... Below is the output of model.write. Everything seems to make sense, any Ideas what I am doing wrong?

Shortest distance from a point to this curve

◇◆丶佛笑我妖孽 提交于 2019-12-01 02:48:50
问题 I need to find the distance of multiple points to a curve of the form: f(x) = a^(k^(bx)) My first option was using its derivative, using a line of the form with the inverse of the derivative, giving it coordinates of the Point and intersecting it with the original curve. Finally, we calculate the distance between points with simple geometry. That's the mathematical process that I usually follow. I need to save time (since I'm doing a genetic algorithms program) so I need an efficient way to

pandas, melt, unmelt preserve index

泪湿孤枕 提交于 2019-12-01 02:02:07
问题 I've got a table of clients (coper) and asset allocation (asset) A = [[1,2],[3,4],[5,6]] idx = ['coper1','coper2','coper3'] cols = ['asset1','asset2'] df = pd.DataFrame(A,index = idx, columns = cols) so my data look like asset1 asset2 coper1 1 2 coper2 3 4 coper3 5 6 and I want to run them through a linear optimization (i've got constraints- somtehing like sum of all of asset_i <= amount_on_hand_i and sum of coper_j = price_j ) so I have to turn this 2D matrix into a 1D vector. Which is easy

Integer linear programming: example and good tools?

跟風遠走 提交于 2019-11-30 22:42:38
Find a vector x which minimizes c . x subject to the constraint m . x >= b, x integer. Here's a sample input set: c : {1,2,3} m : {{1,0,0}, {0,1,0}, {1,0,1}} b : {1,1,1} With output: x = {1,1,0} What are good tools for solving this sort of problem, and examples of how to use them? Mathematica Mathematica has this built in. (NB: Mathematica is not free software.) LinearProgramming[c, m, b, Automatic, Integers] outputs: {1, 1, 0} GLPK I'm offering an answer using GLPK's glpsol , but I hope there are much better ways to do this (it seems like GLPK is overly powerful/general for this kind of

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

独自空忆成欢 提交于 2019-11-30 20:47:57
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, 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,

Integer linear programming: example and good tools?

三世轮回 提交于 2019-11-30 17:49:01
问题 Find a vector x which minimizes c . x subject to the constraint m . x >= b, x integer. Here's a sample input set: c : {1,2,3} m : {{1,0,0}, {0,1,0}, {1,0,1}} b : {1,1,1} With output: x = {1,1,0} What are good tools for solving this sort of problem, and examples of how to use them? 回答1: Mathematica Mathematica has this built in. (NB: Mathematica is not free software.) LinearProgramming[c, m, b, Automatic, Integers] outputs: {1, 1, 0} 回答2: GLPK I'm offering an answer using GLPK's glpsol, but I

binary linear programming solver in Python

馋奶兔 提交于 2019-11-30 16:38:38
问题 I have a Python script in which I need to solve a linear programming problem. The catch is that the solution must be binary. In other words, I need an equivalent of MATLAB's bintprog function. NumPy and SciPy do not seem to have such a procedure. Does anyone have suggestions on how I could do one of these three things: Find a Python library which includes such a function. Constrain the problem such that it can be solved by a more general linear programming solver. Interface Python with MATLAB

Linear Programming (Simplex LP) PuLP?

て烟熏妆下的殇ゞ 提交于 2019-11-30 15:39:28
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.61 2647.82 0 1 Channel2 2700.00 15000 900 1350.00 4050.00 0 2 Channel3 2160.00 12000 333 1080.00 3240.00

PuLP very slow when adding many constraints

好久不见. 提交于 2019-11-30 14:43:28
I'm trying to use PuLP, but it is taking 50 seconds to add 4000 constraints (with 67 variables). Solving the problem only takes a fraction of a second. We want to use PuLP to easily test several solvers on a large set of problems. Should it be taking PuLP this long? Using PyGLPK directly takes only a fraction of second including both setup and solving, so I hope not. What can I do to improve the efficiency of this step in PuLP? Update My constraints matrix is very sparse, and I was able to reduce the setup time to 4 or 5 seconds for this particular problem by only including nonzero

Minimum exact cover of grid with squares; extra cuts

断了今生、忘了曾经 提交于 2019-11-30 08:10:46
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 only has to be fast in practice, not necessarily in the worst case. In the context of this question, I'm