[Cmpl] some CMPL errors

Mike Steglich mike.steglich at th-wildau.de
Sun May 18 07:55:23 EDT 2014


Hi Anna,

If there is a loop fixing the index j you can use the fixed j also for the inner sum loops:

flow  { j in NOHUBNODES : sum{ i in NODES : x[j,i] } - sum{ i in NODES : x[i,j] } = dist[j] * beta; } 

or in short form if both sums uses actually the same set :

flow  { j in NOHUBNODES : sum{ i in NODES : x[j,i]   -  x[i,j] } = dist[j] * beta; } 


Cheers, 

Mike


Am 16.05.2014 um 16:36 schrieb Anna Tarantini <anna.tarantini at hotmail.it>:

> Hello Professor Steglich,
> Thank you for your answer.
> This is our mathematical model.
> 
> 
> Thank you very much for your time.
> Greetings
> Anna 
> 
> Subject: Re: [Cmpl] some CMPL errors
> From: mike.steglich at stegger.net
> Date: Tue, 13 May 2014 09:57:04 +0200
> CC: cmpl at list.coin-or.org
> To: anna.tarantini at hotmail.it
> 
> Hi Anna,
> 
> The first error is easy to solve:
> 
> Please write 
> cost: sum{j in NODES, i in 1..(j-1):  y[i,j]* f + alfa * dist[i,j] * w[i,j] } -> min;
> 
> instead of:
> cost: sum{j in 1..NODES, i in 1..(j-1):  y[i,j]* f + alfa * dist[i,j] * w[i,j] } -> min;
> 
> The problem for the flow and hubFlow constraints is that you use the same index in the outer loop and in the inner sum loops.
> flow  { j in NOHUBNODES : sum{ j in NODES, i in NODES : x[j,i] } - sum{ i in NODES, j in NODES : x[i,j] } = dist[j] * beta; }
> 
> Can you send a mathematical description for a better understanding? 
> 
> Thanks,
> 
> Mike
> 
> 
> 
> 
> 
> Am 12.05.2014 um 17:38 schrieb Anna Tarantini <anna.tarantini at hotmail.it>:
> 
> Hello Professor Steglich. 
> Thank you for your answer. I've tried to modify my model in order to make him functional but I still get some errors. Firstly now I use an instance in which I retrieve my parameters and then I still get the last two errors. I can easily explain all of this pasting you the code so here it is:
> 
> prova.cmpl
> 
> %arg -ignoreZeros
> 
> 
> parameters:
> 
> include "istanza0.cmpl"
> 
> 
> variables:
> 
> w[NODES, NODES]: integer[0..];
> 
> y[NODES, NODES]: integer[0..1];
> 
> x[NODES, NODES]: integer[0..];
> 
> 
> objectives:
> 
> cost: sum{j in 1..NODES, i in 1..(j-1):  y[i,j]* f + alfa * dist[i,j] * w[i,j] } -> min;
> 
> 
> constraints:
> 
> strands { i in NODES, j in NODES : w[i,j] <= k * y[i,j]; }
> 
> flow  { j in NOHUBNODES : sum{ j in NODES, i in NODES : x[j,i] } - sum{ i in NODES, j in NODES : x[i,j] } = dist[j] * beta; }
> 
> hubFlow  { j in NOHUBNODES : sum{ j in NODES : x[j, hub] } - sum{ j in NODES : x[hub,j] } = - sum{ j in NOHUBNODES : dist[j] * beta }; }
> 
> capacity { i in NODES, j in NODES : x[j,i] + x[i,j] <= w[i,j] * omega; }
> 
> istanza0.cmpl
> 
> NODES := 1..12;
> NOHUBNODES := 1..11;
> hub := 12;
> 
> LINKS := 1..15;
> 
> k := 9;
> 
> links[LINKS, 1(1)3] := ((1, 2, 124.42),
> 		    (2, 5, 6887.90),
> 		    (2, 6, 84.81),
> 		    (2, 12, 944.68),
> 		    (3, 6, 162.52),
> 		    (3, 9, 1518.29),
> 		    (4, 7, 935.30),
> 		    (4, 10, 1898.83),
> 		    (4, 11, 1945.26),
> 		    (5, 7, 161.04),
> 		    (5, 8, 2530.56),
> 		    (6, 7, 1160.86),
> 		    (8, 10, 459.26),
> 		    (9, 12, 344.35),
> 		    (10, 11, 604.96));
> 
> alfa := 133;
> 
> f := 1081;
> 
> beta := 20;
> 
> omega := 7;
> 
> dist[NODES] := (591, 901, 260, 1147, 745, 1516, 1573, 1028, 2196, 903, 505, 0);
> 
> 
> And finally here are the errors:
> 
> error(compiler): file prova.cmpl line 20: A set can contain only integer and strings, but no other sets
> error(compiler): file prova.cmpl line 27: syntax error, unexpected ASSIGN_ITER, expecting ':'
> error(compiler): file prova.cmpl line 29: syntax error, unexpected ASSIGN_ITER, expecting ':'
> error(compiler): file prova.cmpl line 29: syntax error, unexpected '}', expecting end of file
> 
> Thank you very much for your time.
> Greetings
> Anna 
> 
> Subject: Re: [Cmpl] some CMPL errors
> From: mike.steglich at stegger.net
> Date: Mon, 5 May 2014 17:30:30 +0200
> CC: cmpl at list.coin-or.org; t.schleiff at gmail.com
> To: anna.tarantini at hotmail.it
> 
> Hi Anna,
> 
> I apologize the very delayed answer. There was obesely a misunderstanding between me and Thomas (my teammate) who shout answer you.
>  Please see my answers below:
>  
> Am 30.04.2014 um 17:24 schrieb Anna Tarantini <anna.tarantini at hotmail.it>:
> 
> Hi, we're trying to formulate a simple model to get the layout of a MAN. 
> While compiling the CMPL we get some errors:
> 
> error(compiler): file prova.cmpl line 55: syntax error, unexpected SYMBOL_VAR
> error(compiler): file prova.cmpl line 64: syntax error, unexpected ASSIGN_ITER, expecting ':'
> error(compiler): file prova.cmpl line 64: syntax error, unexpected '}', expecting end of file
> 
> here's the CMPL file 
> 
> 
> 
> %arg -ignoreZeros
> 
> 
> 
> parameters:
> 
> f:=30;
> alfa:=40;
> r:=(1,2,3,4,5);
> beta:=20;
> omega:=10;
> 
> seed:=srand(100);
> 	M:=10000;
> 
> 	nrOfCities:=5;
> 	NODES:=1..nrOfCities;
> 
> 	{i in NODES:
> 		  xp[i]:=rand(100);
> 		  yp[i]:=rand(100);
> 	}
> 
> 	{i in NODES, j in NODES:
> 	    {i==j: 
> 		dist[i,j]:=M; |
> 	    default: 
> 		dist[i,j]:= sqrt( (xp[i]-xp[j])^2 + (yp[i]-yp[j])^2 );
> 		dist[j,i]:= dist[i,j]+rand(10)-rand(10);
> 	    }
> 	}
> 
> 
> #include "istanza0.cmpl"
> 
> 
> variables:
> 
> 
> 
> w[NODES, NODES]: integer[0..];
> 
> y[NODES, NODES]: integer[0..1];
> 
> x[NODES, NODES]: integer[0..];
> 
> 
> 
> objectives:
> 
> 
> 
> cost: (sum{j:=1..nrOfCities : sum{i:=1..(j-1):  y[i,j] }} * f) +
>       
>      (alfa * sum{j:=1..nrOfCities: sum{i:=1..(j-1):  d[i,j] * w[i,j] }}) -> min;
> 
> The parameter array d[,] is not defined. I would assume that you want to use dist[,]. You can additionally simplify your objective function because the two sums run over the same sets.
> 
> This is my proposal:
> 
> cost: sum{j in 1..nrOfCities, i in 1..(j-1):  y[i,j]* f + alfa * dist[i,j] * w[i,j] } -> min;
> 
> 
> 
> 
> 
> 
> 
> constraints:
> 
> strands { i in NODES, j in NODES : w[i,j] <= k * y[i,j]; }
> 
> k is not defined.
> 
> 
> 
> 
> flow  { j in NODES-1 : sum{ j in NODES, i in NODES : x[j,i] } - sum{ i in NODES, j in NODES : x[i,j] } = r[j] * beta; }
> 
> hubFlow  { j in NODES-1 : sum{ j in NODES : x[j, NODES] } - sum{ j in NODES : x[NODES,j] } = - sum{ j in NODES-1 : r[j] * beta }; }
> 
> This is a little bit more difficult to answer:
> Do you want really to use the index j in the outer and the inner sums? If not please use another index for the outer sum. Do you mean j in (1..nrOfCities-1)  instead j in NODES-1. In my mind does make NODES-1 not really sense. 
> 
> I do not understand the idea of  x[j, NODES].  Do you want to address a single element of the array x[,] or the vector out of the matrix x[,]?
>  
> 
> 
> capacity { i in NODES, j in NODES : x[j,i] + x[i,j] <= w[i,j] * omega; }
> 
> 
> 
> Any clue of how to resolve those errors?
> Greetings
> 
> 
> Thanks,
> 
> Mike
> 
> 
> 
> 
> Anna
> _______________________________________________
> Cmpl mailing list
> Cmpl at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cmpl
> 
> 
> <modIng.pdf>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cmpl/attachments/20140518/ea7148d3/attachment.html>


More information about the Cmpl mailing list