Re: [Help-glpk] piecewise linear function

2018-02-15 Thread Andrew Makhorin
On Thu, 2018-02-15 at 21:21 +0100, Heinrich Schuchardt wrote:
> Hello Giovanni,
> 
> please, read doc/gmpl.pdf which comes with the GLPK source.
> 
> The <<>> syntax may exist in AMPL but it does not exist in GMPL.
> 
> Depending on your piecewise linear function being concave or convex
> you can replace it with some linear constraints or you will have to
> introduce extra binary variables.

Please see http://en.wikibooks.org/wiki/GLPK/Modeling_tips .

> 
> Best regards
> 
> Heinrich
> 
> Am 15.02.18, 21:10, Giovanni Di Stasi 
> schrieb:
> I am trying to use such functions but I get a syntax error. 
> In particular, this is my program, taken by the following book
> chapter:
> 
> 
> https://ampl.com/BOOK/CHAPTERS/20-piecewise.pdf
> 
> 
> 
> set ORIG; # origins
> set DEST; # destinations
> param supply {ORIG} >= 0; # amounts available at origins
> param demand {DEST} >= 0; # amounts required at destinations
> check: sum {i in ORIG} supply[i] = sum {j in DEST} demand[j];
> param rate1 {i in ORIG, j in DEST} >= 0;
> param rate2 {i in ORIG, j in DEST} >= rate1[i,j];
> param rate3 {i in ORIG, j in DEST} >= rate2[i,j];
> param limit1 {i in ORIG, j in DEST} > 0;
> param limit2 {i in ORIG, j in DEST} > limit1[i,j];
> var Trans {ORIG,DEST} >= 0; # units to be shipped
> minimize Total_Cost: sum {i in ORIG, j in DEST}
> < rate1[i,j], rate2[i,j], rate3[i,j]>> Trans[i,j];
> subject to Supply {i in ORIG}:
> sum {j in DEST} Trans[i,j] = supply[i];
> subject to Demand {j in DEST}:
> sum {i in ORIG} Trans[i,j] = demand[j];
> 
> 
> 
> 
> When I try to make glpk parse it, I get the following error:
> 
> 
> glpsol --model glpk/Test --data /tmp/DATAg5ZQ0L
> -w /tmp/OUTXlm0ST
> GLPSOL: GLPK LP/MIP Solver, v4.61
> Parameter(s) specified in the command line:
>  --model glpk/Test --data /tmp/DATAg5ZQ0L -w /tmp/OUTXlm0ST
> Reading model section from glpk/Test...
> glpk/Test:14: syntax error in expression
> Context: ...>= 0 ; minimize Total_Cost : sum { i in ORIG , j
> in DEST } <
> MathProg model processing error
> 
> 
> 
> 
> I really have no clue as of now.
> 
> 
> Thanks
> 
> 
> 
> 
> 
> ___ Help-glpk
> mailing list Help-glpk@gnu.org
> https://lists.gnu.org/mailman/listinfo/help-glpk
> ___
> Help-glpk mailing list
> Help-glpk@gnu.org
> https://lists.gnu.org/mailman/listinfo/help-glpk



___
Help-glpk mailing list
Help-glpk@gnu.org
https://lists.gnu.org/mailman/listinfo/help-glpk


Re: [Help-glpk] piecewise linear function

2018-02-15 Thread Heinrich Schuchardt
Hello Giovanni,

please, read doc/gmpl.pdf which comes with the GLPK source.

The <<>> syntax may exist in AMPL but it does not exist in GMPL.

Depending on your piecewise linear function being concave or convex you can replace it with some linear constraints or you will have to introduce extra binary variables.

Best regards

Heinrich
Am 15.02.18, 21:10, Giovanni Di Stasi  schrieb:
I am trying to use such functions but I get a syntax error. In particular, this is my program, taken by the following book chapter:https://ampl.com/BOOK/CHAPTERS/20-piecewise.pdfset ORIG; # originsset DEST; # destinationsparam supply {ORIG} >= 0; # amounts available at originsparam demand {DEST} >= 0; # amounts required at destinationscheck: sum {i in ORIG} supply[i] = sum {j in DEST} demand[j];param rate1 {i in ORIG, j in DEST} >= 0;param rate2 {i in ORIG, j in DEST} >= rate1[i,j];param rate3 {i in ORIG, j in DEST} >= rate2[i,j];param limit1 {i in ORIG, j in DEST} > 0;param limit2 {i in ORIG, j in DEST} > limit1[i,j];var Trans {ORIG,DEST} >= 0; # units to be shippedminimize Total_Cost: sum {i in ORIG, j in DEST}> Trans[i,j];subject to Supply {i in ORIG}:sum {j in DEST} Trans[i,j] = supply[i];subject to Demand {j in DEST}:sum {i in ORIG} Trans[i,j] = demand[j];When I try to make glpk parse it, I get the following error:glpsol --model glpk/Test --data /tmp/DATAg5ZQ0L -w /tmp/OUTXlm0STGLPSOL: GLPK LP/MIP Solver, v4.61Parameter(s) specified in the command line: --model glpk/Test --data /tmp/DATAg5ZQ0L -w /tmp/OUTXlm0STReading model section from glpk/Test...glpk/Test:14: syntax error in _expression_Context: ...>= 0 ; minimize Total_Cost : sum { i in ORIG , j in DEST } 

[Help-glpk] piecewise linear function

2018-02-15 Thread Giovanni Di Stasi
I am trying to use such functions but I get a syntax error.
In particular, this is my program, taken by the following book chapter:

https://ampl.com/BOOK/CHAPTERS/20-piecewise.pdf

set ORIG; # origins
set DEST; # destinations
param supply {ORIG} >= 0; # amounts available at origins
param demand {DEST} >= 0; # amounts required at destinations
check: sum {i in ORIG} supply[i] = sum {j in DEST} demand[j];
param rate1 {i in ORIG, j in DEST} >= 0;
param rate2 {i in ORIG, j in DEST} >= rate1[i,j];
param rate3 {i in ORIG, j in DEST} >= rate2[i,j];
param limit1 {i in ORIG, j in DEST} > 0;
param limit2 {i in ORIG, j in DEST} > limit1[i,j];
var Trans {ORIG,DEST} >= 0; # units to be shipped
minimize Total_Cost: sum {i in ORIG, j in DEST}
<> Trans[i,j];
subject to Supply {i in ORIG}:
sum {j in DEST} Trans[i,j] = supply[i];
subject to Demand {j in DEST}:
sum {i in ORIG} Trans[i,j] = demand[j];


When I try to make glpk parse it, I get the following error:

glpsol --model glpk/Test --data /tmp/DATAg5ZQ0L -w /tmp/OUTXlm0ST
GLPSOL: GLPK LP/MIP Solver, v4.61
Parameter(s) specified in the command line:
 --model glpk/Test --data /tmp/DATAg5ZQ0L -w /tmp/OUTXlm0ST
Reading model section from glpk/Test...
glpk/Test:14: syntax error in expression
Context: ...>= 0 ; minimize Total_Cost : sum { i in ORIG , j in DEST } <
MathProg model processing error


I really have no clue as of now.

Thanks
___
Help-glpk mailing list
Help-glpk@gnu.org
https://lists.gnu.org/mailman/listinfo/help-glpk


Re: [Help-glpk] Piecewise Linear Function

2009-02-27 Thread Andrew Makhorin
> I have a piecewise linear function like this:
> [...]

> This function represents the constraints in a MILP.


> To solve this MILP I have to convex my function, but I don't know like
> do it.

> Somebody can help me?

See:
http://lists.gnu.org/archive/html/help-glpk/2008-12/msg00126.html
http://lists.gnu.org/archive/html/help-glpk/2007-06/msg5.html




___
Help-glpk mailing list
Help-glpk@gnu.org
http://lists.gnu.org/mailman/listinfo/help-glpk


[Help-glpk] Piecewise Linear Function

2009-02-27 Thread Simone Atzeni
Hi,


I have a piecewise linear function like this:




\[ 

h_i({\bf x},{\bf u})= 

\begin{cases} 

A_1({\bf x}) + {\bf u} (B_1({\bf x}) - A_1({\bf x})),   \text{se $0 \le {\bf u} 
< 1$} \\ 

B_1({\bf x}) + ({\bf u}-1) (B_2({\bf x}) - B_1({\bf x})),   \text{se $1 \le 
{\bf u} < 2$} \\ 

B_2({\bf x}) + ({\bf u}-2) (B_3({\bf x}) - B_2({\bf x})),   \text{se ${\bf u} 
\ge 2$} \\ 

\end{cases} 

\] 




where:




\begin{itemize} 

\item $A_1({\bf x}) = 3x$

\item $B_1({\bf x}) = 4x$

\item $B_2({\bf x}) = 5x$

\item $B_3({\bf x}) = 6x$

\end{itemize} 




This function represents the constraints in a MILP.




To solve this MILP I have to convex my function, but I don't know like do it.




Somebody can help me?




Thanks

Simone




Hi,I have a piecewise linear function like this:\[ h_i({\bf x},{\bf u})= \begin{cases} A_1({\bf x}) + {\bf u} (B_1({\bf x}) - A_1({\bf x})), & \text{se $0 \le {\bf u} < 1$} \\ B_1({\bf x}) + ({\bf u}-1) (B_2({\bf x}) - B_1({\bf x})), & \text{se $1 \le {\bf u} < 2$} \\ B_2({\bf x}) + ({\bf u}-2) (B_3({\bf x}) - B_2({\bf x})), & \text{se ${\bf u} \ge 2$} \\ \end{cases} \] where:\begin{itemize} \item $A_1({\bf x}) = 3x$\item $B_1({\bf x}) = 4x$\item $B_2({\bf x}) = 5x$\item $B_3({\bf x}) = 6x$\end{itemize} This function represents the constraints in a MILP.To solve this MILP I have to convex my function, but I don't know like do it.Somebody can help me?ThanksSimone
___
Help-glpk mailing list
Help-glpk@gnu.org
http://lists.gnu.org/mailman/listinfo/help-glpk