|
View:
New views
7 Messages
—
Rating Filter:
Alert me
|
|
|
Usage of Summation in LP SolveHi,
I'm a new user of lp_solve version 5.5.0.15. It looks incredibly user-friendly and easy to use, but I am not sure if there is a way, without using external language, to key in constraints involving summation? More specifically, a few of my constraints involve something like Summation (from i = 1 to i = 30) * Summation (from j = 1 to j = 20) * function For the above case, also, how do I declare "i" and "j", knowing that they are just subscripts to variables, (i.e. Fi = ki + ....) There doesn't seem to have an issue addressing summation in th lp_solve refernce guide and I do not know the names for "i" and "j"so I have difficulty searching for help regarding this issue too. Many thanks in advance. Stan |
|
|
RE: Usage of Summation in LP SolveSee the references to GNU Mathprog from the search page of the online docs.
It is a model description language that includes sets and summation and data separation from structure. http://lpsolve.sourceforge.net/5.5/ http://lpsolve.sourceforge.net/5.5/MathProg.htm http://lpsolve.sourceforge.net/5.5/XLI.htm It is easiest to use via the solver IDE. http://lpsolve.sourceforge.net/5.5/IDE.htm Here is an example /* QUEENS, a classic combinatorial optimization problem */ /* Written in GNU MathProg by Andrew Makhorin <mao@...> */ /* The Queens Problem is to place as many queens as possible on the 8x8 (or more generally, nxn) chess board in a way that they do not fight each other. This problem is probably as old as the chess game itself, and thus its origin is not known, but it is known that Gauss studied this problem. */ param n, integer, > 0, default 8; /* size of the chess board */ var x{1..n, 1..n}, binary; /* x[i,j] = 1 means that a queen is placed in square [i,j] */ s.t. a{i in 1..n}: sum{j in 1..n} x[i,j] <= 1; /* at most one queen can be placed in each row */ s.t. b{j in 1..n}: sum{i in 1..n} x[i,j] <= 1; /* at most one queen can be placed in each column */ s.t. c{k in 2-n..n-2}: sum{i in 1..n, j in 1..n: i-j == k} x[i,j] <= 1; /* at most one queen can be placed in each "\"-diagonal */ s.t. d{k in 3..n+n-1}: sum{i in 1..n, j in 1..n: i+j == k} x[i,j] <= 1; /* at most one queen can be placed in each "/"-diagonal */ maximize obj: sum{i in 1..n, j in 1..n} x[i,j]; /* objective is to place as many queens as possible */ /* solve the problem */ solve; end _____ From: lp_solve@... [mailto:lp_solve@...] On Behalf Of stanleyy_2000 Sent: Saturday, October 24, 2009 4:49 AM To: lp_solve@... Subject: [lp_solve] Usage of Summation in LP Solve Hi, I'm a new user of lp_solve version 5.5.0.15. It looks incredibly user-friendly and easy to use, but I am not sure if there is a way, without using external language, to key in constraints involving summation? More specifically, a few of my constraints involve something like Summation (from i = 1 to i = 30) * Summation (from j = 1 to j = 20) * function For the above case, also, how do I declare "i" and "j", knowing that they are just subscripts to variables, (i.e. Fi = ki + ....) There doesn't seem to have an issue addressing summation in th lp_solve refernce guide and I do not know the names for "i" and "j"so I have difficulty searching for help regarding this issue too. Many thanks in advance. Stan |
|
|
Re: Usage of Summation in LP SolveAll summation of a summation can be developed as a single summation, and hence, a linear equation...
--- In lp_solve@..., "stanleyy_2000" <stanleyy_2000@...> wrote: > > Hi, > > I'm a new user of lp_solve version 5.5.0.15. > > It looks incredibly user-friendly and easy to use, but I am not sure if there is a way, without using external language, to key in constraints involving summation? > > More specifically, a few of my constraints involve something like Summation (from i = 1 to i = 30) * Summation (from j = 1 to j = 20) * function > > For the above case, also, how do I declare "i" and "j", knowing that they are just subscripts to variables, (i.e. Fi = ki + ....) > > There doesn't seem to have an issue addressing summation in th lp_solve refernce guide and I do not know the names for "i" and "j"so I have difficulty searching for help regarding this issue too. > > Many thanks in advance. > > Stan > |
|
|
Re: Usage of Summation in LP SolveAnd an alternative is ZIMPL, used in the same way as MathProg.
Peter On Sat, Oct 24, 2009 at 4:44 PM, William H. Patton <pattonwh@...>wrote: > > > See the references to GNU Mathprog from the search page of the online > docs. > > It is a model description language that includes sets and summation and > data separation from structure. > > http://lpsolve.sourceforge.net/5.5/ > > http://lpsolve.sourceforge.net/5.5/MathProg.htm > > http://lpsolve.sourceforge.net/5.5/XLI.htm > > > > It is easiest to use via the solver IDE. > > http://lpsolve.sourceforge.net/5.5/IDE.htm > > > > Here is an example > > /* QUEENS, a classic combinatorial optimization problem */ > > > > /* Written in GNU MathProg by Andrew Makhorin <mao@...> */ > > > > /* The Queens Problem is to place as many queens as possible on the 8x8 > > (or more generally, nxn) chess board in a way that they do not fight > > each other. This problem is probably as old as the chess game itself, > > and thus its origin is not known, but it is known that Gauss studied > > this problem. */ > > > > param n, integer, > 0, default 8; > > /* size of the chess board */ > > > > var x{1..n, 1..n}, binary; > > /* x[i,j] = 1 means that a queen is placed in square [i,j] */ > > > > s.t. a{i in 1..n}: sum{j in 1..n} x[i,j] <= 1; > > /* at most one queen can be placed in each row */ > > > > s.t. b{j in 1..n}: sum{i in 1..n} x[i,j] <= 1; > > /* at most one queen can be placed in each column */ > > > > s.t. c{k in 2-n..n-2}: sum{i in 1..n, j in 1..n: i-j == k} x[i,j] <= 1; > > /* at most one queen can be placed in each "\"-diagonal */ > > > > s.t. d{k in 3..n+n-1}: sum{i in 1..n, j in 1..n: i+j == k} x[i,j] <= 1; > > /* at most one queen can be placed in each "/"-diagonal */ > > > > maximize obj: sum{i in 1..n, j in 1..n} x[i,j]; > > /* objective is to place as many queens as possible */ > > > > /* solve the problem */ > > solve; > > > > end > > > > > ------------------------------ > > *From:* lp_solve@... [mailto:lp_solve@...] *On > Behalf Of *stanleyy_2000 > *Sent:* Saturday, October 24, 2009 4:49 AM > *To:* lp_solve@... > *Subject:* [lp_solve] Usage of Summation in LP Solve > > > > > > Hi, > > I'm a new user of lp_solve version 5.5.0.15. > > It looks incredibly user-friendly and easy to use, but I am not sure if > there is a way, without using external language, to key in constraints > involving summation? > > More specifically, a few of my constraints involve something like Summation > (from i = 1 to i = 30) * Summation (from j = 1 to j = 20) * function > > For the above case, also, how do I declare "i" and "j", knowing that they > are just subscripts to variables, (i.e. Fi = ki + ....) > > There doesn't seem to have an issue addressing summation in th lp_solve > refernce guide and I do not know the names for "i" and "j"so I have > difficulty searching for help regarding this issue too. > > Many thanks in advance. > > Stan > > > |
|
|
integer variablesI tried to solve the example from the help page for integer variables using
LPSolve IDE 5.5.0.15. min: -x1 -2 x2 +0.1 x3 +3 x4; r_1: +x1 +x2 <= 5; r_2: +2 x1 -x2 >= 0; r_3: -x1 +3 x2 >= 0; r_4: +x3 +x4 >= 0.5; x3 >= 1.1; int x3; The solution I get for x3 is 1.1 . What am I doing wrong? Please help. Sisira |
|
|
Re: integer variablesI can only imagine that you checked the checkbox to ignore integer restrictions in the settings of the IDE.
Peter --- In lp_solve@..., "Sisira Jayasinghe" <sisirajaya@...> wrote: > > I tried to solve the example from the help page for integer variables using > LPSolve IDE 5.5.0.15. > > > > min: -x1 -2 x2 +0.1 x3 +3 x4; > > r_1: +x1 +x2 <= 5; > > r_2: +2 x1 -x2 >= 0; > > r_3: -x1 +3 x2 >= 0; > > r_4: +x3 +x4 >= 0.5; > > x3 >= 1.1; > > > > int x3; > > > > The solution I get for x3 is 1.1 . > > > > What am I doing wrong? Please help. > > > > Sisira > |
|
|
RE: Re: integer variablesHi Peter:
You are correct that setting was checked. But that was by default, out of the box. I did not make any settings changes. Thank you very much for your quick help. Sisira From: lp_solve@... [mailto:lp_solve@...] On Behalf Of peter_notebaert Sent: Tuesday, November 03, 2009 9:32 AM To: lp_solve@... Subject: [lp_solve] Re: integer variables I can only imagine that you checked the checkbox to ignore integer restrictions in the settings of the IDE. Peter --- In lp_solve@... <mailto:lp_solve%40yahoogroups.com> , "Sisira Jayasinghe" <sisirajaya@...> wrote: > > I tried to solve the example from the help page for integer variables using > LPSolve IDE 5.5.0.15. > > > > min: -x1 -2 x2 +0.1 x3 +3 x4; > > r_1: +x1 +x2 <= 5; > > r_2: +2 x1 -x2 >= 0; > > r_3: -x1 +3 x2 >= 0; > > r_4: +x3 +x4 >= 0.5; > > x3 >= 1.1; > > > > int x3; > > > > The solution I get for x3 is 1.1 . > > > > What am I doing wrong? Please help. > > > > Sisira > |
| Free embeddable forum powered by Nabble | Forum Help |