linear-programming,integer-programming
Rewriting loannis's answer in a linear form by expanding out multiplication of binary variables with a continuous variable: Tc <= M*Y Tc <= A Tc >= A - M*(1-Y) Tc >= 0 Tc <= X Td <= M*Y Td <= B Td >= B - M*(1-Y) Td >= 0 X...
gnu,linear-programming,linear,ampl,glpk
You can do it as follows: s.t. rest: x['Persones'] >= 7; ...
algorithm,linear-programming,network-flow
Model the problem as a bipartite graph: put the examinations as vertices on the left side and the instruments on the right side. Connect examinations to their instruments via edges of infinite capacity. Now introduce a source S and a sink T. Connect S to the examinations via edges that...
The R-squared, adjusted R-squared, and all other values you see in the summary are accessible from within the summary object. You can see everything by using str(summary(M.lm)): > str(summary(M.lm)) # Truncated output... List of 11 $ call : language lm(formula = MaxSalary ~ Score, data = salarygov) $ terms :Classes...
optimization,mathematical-optimization,linear-programming,scientific-computing,integer-programming
Edit: Setting Variable2 equal to min or max of Variable1 and Parameter. min(Parameter,Variable1): If you are sure that Variable2 "wants" to be small in the objective function, then you just need to require Variable2 to be less than or equal to both Parameter and Variable1: Variable2 <= Variable1 Variable2 <=...
r,linear-programming,lpsolve,absolute-value,lpsolveapi
To model |x| in an LP, you typically create two new variables, x^- and x^+. Constrain them both to be nonnegative: x^-, x^+ >= 0 Then each time you have x in your model, replace it with x^+ - x^-, and each time you have |x|, replace it with x^+...
matlab,math,linear-programming
I'm assuming that the entries of W are positive; negative numbers don't make much sense in the context of your problem (since you're truncating at 1 and not at -1), while zeros contribute nothing and can be removed with nonzeros command. Here's how you can solve for a: Sort W...
Yes, you can set a custom basis by using glp_set_col_stat(). You will have to set each column to be Basic (GLP_BS) or Non-basic (GLP_NL). You could also use the API glp_adv_basis method, though I don't think it lets you customize the basis. I recommend the very readable Section 2.6 in...
Documentation of ?simplex for argument b2 states that A vector of length m2 giving the right hand side of the >= constraints. This argument is required if A2 is given and ignored otherwise. All values in b2 must be non-negative. Note that the constraints x >= 0 are included automatically...
The parameters Aeq and beq represent linear equality constraints. Each row of Aeq has the coefficients of an equation, and the corresponding row of beq is the right hand side. Therefore, the number of rows in Aeq and beq must be the same. Also, the number of rows of c...
r,memory-management,matrix,linear-programming
This was my concern before. By running mat[...] you are converting the big.matrix in to a regular matrix. The function will need to be rewritten so it is compatible with big.matrix objects. If you look at the source code for R_symphony_solve_LP you will find the following call: out <- .C("R_symphony_solve",...
variables,indexing,set,linear-programming,ampl
In AMPL, you can create or define your own "sets" for valid indices and use them in your constraints. So, in your case, to avoid invalid indices, you can define a set of permissible indices: param inner_i {2..(N-1)} and loop over those when creating the constraints. The price we pay...
matlab,octave,linear-programming,glpk
I could sort out my problem. It is happening because of some of the variables are having value 0.000000000000000027773 or 0.99999999999999999. So if I do some pre-processing like making those 0.000000000000027773 values 0 or 0.99999999999999999 1 then GLPK gives feasible solution
algorithm,search,optimization,dynamic-programming,linear-programming
Assuming that you are allowed to have fractional grams of food items, you can solve this problem analytically, see http://en.wikipedia.org/wiki/Linear_least_squares_%28mathematics%29 for details. You have the additional implicit constraint that none of the foods can be present in negative amount. So if foods appear in a negative amount, you will need...
mathematical-optimization,linear-programming,integer-programming,quadratic-programming
Models in this form are actually called bilinear optimization problems. The typical approach to linearizing bilinear terms is through something called the McCormick envelope. Consider variables x and y, where you want x*y in the objective of your maximization problem. If we assume x and y are bounded by xL...
Try something like for (i=0; i<numNodes; i++) { if (i == 0) { IloExpr expr1(env); for (j=0; j<numIn[0]; j++) expr1 += x[EInIndex[0][j]]; IloExpr expr2(env); expr2 += x[EOutIndex[0][j]]; model.add(expr1 - expr2 == -1); } else if ((i >= 1) && (i < n/2)) { // etc } else { // etc...
matlab,octave,linear-programming,glpk
If you look at the octave help you will find this lpsolver (default: 1) Select which solver to use. If the problem is a MIP problem this flag will be ignored. 1 Revised simplex method. 2 Interior point method. So really in only differs on terms of efficiency in certain...
r,memory,64bit,linear-programming
It would be best if you could also provide the 'line for the linear program' but my comment is too long to put above. @James is correct that 32-bit is hard-coded in to bigmemory at the moment. After glancing at the source on github I see the author did remove...
mathematical-optimization,modeling,linear-programming,gurobi
Gurobi isn't stalling. It has found a solution within 0.11% of optimal and is continuing to try to improve the bound to 0.01%. If you want to stop it sooner, you should change the parameter MIPGap. To actually make Gurobi faster, you can try changing other parameters with the Tuning...
python,linear-programming,pulp
This seems to be caused by an error with the older version of cbc shipped with pulp 1.5.6 I will repackage a newer version of cbc with pulp 1.5.7 ASAP. Also you can use your other version of CBC (if it is on the path) by using the COIN_CMD solver.
Yes, you can do this by introducing a new binary variable. (Note that we are modifying the underlying formulation, not tinkering with CPLEX per se for the modulo.) Your constraints are x1 + x2 + x3 = 0 OR 2 Let's introduce a new binary variable Y and rewrite the...
python,scipy,linear-programming
Here is a wrapper that incorporates lower bound rows in the lingprog formulation. Note that more error trapping is necessary (for example, the number of columns of each A matrix need to be equal), this is not meant to be a robust implementation. For proper error trapping, I suggest you...
algorithm,graph,graph-algorithm,linear-programming,np-complete
It's possible to formulate this as the following problem. Suppose each vertex v in the graph has weight w(v). You define a variable x(v), and use some out-of-the-box linear programming solver to solve max \sum_v w(v) x(v) (maximize the weight of chosen vertices) subject to x(u) + x(v) <= 1,...
r,regression,mathematical-optimization,linear-programming,minimization
Because Quw and ruw are both data, all constraints as well as the objective are linear in the yuw decision variables. As a result, this is a linear programming problem that can be approached by the lpSolve package. To abstract this out a bit, let's assume R=20 and C=10 describe...
linear-programming,ampl,lpsolve
You should put (a link to) the liblpsolve55.so somewhere on the library search paths, for example /usr/lib: $ sudo ln -s /usr/lib/lp_solve/liblpsolve55.so /usr/lib Also make sure that you have 32-bit (x86) version of liblpsolve55.so installed. For example, on 64-bit Ubuntu you can install 32-bit version of liblpsolve55.so as follows: $...
matlab,for-loop,matrix,vectorization,linear-programming
One vectorized approach with bsxfun - A(bsxfun(@plus,ii(:),(jj-1)*size(A,1))) = x You need the expansion with bsxfun as the number of row indices don't match up with the number of column indices. Also, please note that I have replaced the variable names i with ii and j with jj as i and...
For each i such that the ith edge is not in T, for each j such that the jth edge lies on the unique path in T from one endpoint of the ith edge to the other, there is a constraint wi' - wj' ≥ 0.
constraints,linear-programming,ampl
The problem is that you use the same index c name in two different indexing expressions with overlapping scope, (c,r) in GROUP and c in COUNTRY. You can rename the second index to avoid the error: subject to WITHIN_REGION{r in REGION, (c,r) in GROUP, l in LOAN_DURATION}: x[c,l] <= QUOTA[r]*sum{c2...
matlab,math,curve-fitting,linear-programming,least-squares
You want to find an approximate solution x to A x = b in the least-squares sense, i.e. you want to minimize ||A x - b||2 = xT AT A x + bT b - 2 xT AT b. Disregarding the constant term bTb and dividing by a factor 2,...
optimization,mathematical-optimization,linear-programming,scientific-computing,integer-programming
First create a binary variable that equals 1 if Variable1 > 0 and 0 if Variable1 < 0: Variable1 <= UB * BinaryVar LB * (1 - BinaryVar) <= Variable1 (If Variable1 > 0, then BinaryVar must equal 1. If Variable1 < 0, then BinaryVar must equal 0. Note that...
linear-programming,solver,ms-solver-foundation
(Note: no new releases of Solver Foundation are forthcoming - it's essentially been dropped by Microsoft.) The stack trace indicates that this is a bug in the simplex solver's presolve routine. Unfortunately the SimplexDirective does not have a way to disable presolve (unlike InteriorPointDirective). Therefore the way to get around...
python,mathematical-optimization,linear-programming,gurobi,integer-programming
To obtain the best feasible answer so far, you should first verify that there is a feasible solution by checking the Status attribute on your model object, then querying the X attribute on your variable objects. If you have named your variables (with the name parameter on e neat way...
openshift,linear-programming,gurobi
I assume that your shell is bash on the server (echo $SHELL should return /bin/bash, you can check if you are unsure). You need to: Copy the archive gurobi6.0.0_linux64.tar.gz to your home directory and extract it: tar xvfz gurobi6.0.0_linux64.tar.gz`) This should create a subdirectory gurobi600_linux in your home directory. Check...
python,r,large-data,linear-programming
The package lpSolveAPI can solve long-vector linear programming problems. You have to first start my declaring a Linear Programming object, then add the constraints: library(lpSolveAPI) #Generate Linear Programming Object lprec <- make.lp(nrow = 0 # Number of Constraints , ncol = ncol(mat) # Number of Decision Variables ) #Set Objective...
optimization,linear-programming
This can be formulated as a mixed integer linear program. This is a linear program where some of the variables are constrained to be integer. Contrary to linear programs, solving the general integer program is NP-hard. However, there are many commercial or open source solvers that can solve efficiently large-scale...
algorithm,linear-algebra,linear-programming,cplex,traveling-salesman
According to this Wikipedia article the travelling salesman problem can be modelled as an integer linear program, which I believe to be the key issue of the question. The idea is to have decision variables of permitted values in {0,1} which model selected edges in the graph. Suitable constraints must...
python,linear-programming,gurobi,integer-programming
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 varaible x = m.addVar(lb=0, ub=1, vtype=GRB.CONTINUOUS) You can set it's attribe x.vtype = GRB.BINARY You can see...