[Help-glpk] Transforming a Piecewise Linear Functions in a Convex Predicate

2009-05-11 Thread Simone Atzeni

Hi,

I need to transform a Piecewise Linear Functions in a Convex  
Predicate. In attachment there is a tex file with the function and my  
transformation in a convex predicate. Using that convex predicate in a  
milp, the milp does not found solution. So in attachment there is  
my .c file with the function that create the MILP and an output with a  
milp with random valute.
The function in the examples is repeated two times, but it does not  
matter.


I don't know where is my mistake. It's impossible for me find it.

Thank you for your help.
Cheers
Simone



Piecewise-Linear-Functions.tex
Description: Binary data


function.c
Description: Binary data
Maximize
 obj: 0.5 Z.1 + 0.5 Z.2

Subject To
 r.1: + 5.6 U.1   -1 Z.1 + 72.8 Y.1.1 <= 56
 r.2:   -5.6 U.1 + 1 Z.1   -15.8 Y.1.1 <= 1
 r.3: + 1 U.1 + 10 Q.1 <= 10
 r.4:   -1 U.1 + 1 Q.2 <= 0
 r.5: - 1 Q.1 - 1 Q.2 - 1 Y.1.1 <= -1
 r.6: + 5.6 U.1   -1 Z.1 + 72.8 Y.1.2 <= 56
 r.7:   -5.6 U.1 + 1 Z.1   -15.8 Y.1.2 <= 1
 r.8: + 1 U.1 + 9 Q.3 <= 10
 r.9: -1 U.1 + 2 Q.4 <= 0
 r.10: - Q.3 - Q.4 - Y.1.2 <= -1
 r.11: + 5.6 U.1   -1 Z.1 + 72.8 Y.1.3 <= 56
 r.12:   -5.6 U.1 + 1 Z.1   -15.8 Y.1.3 <= 1
 r.13: -8 Y.1.3 + 1 U.1 <= 2
 r.14: + 11.2 U.1   -1 Z.2 + 128.8 Y.1.1 <= 112
 r.15:   -11.2 U.1 + 1 Z.2   -15.8 Y.1.1 <= 1
 r.16: + 1 U.1 + 10 Q.1 <= 10
 r.17:   -1 U.1 + 1 Q.2 <= 0
 r.18: - 1 Q.1 - 1 Q.2 - 1 Y.1.1 <= -1
 r.19: + 0 U.1   -1 Z.2 + 28 Y.1.2 <= 0
 r.20: + 0 U.1 + 1 Z.2   -27 Y.1.2 <= 1
 r.21: + 1 U.1 + 9 Q.3 <= 10
 r.22: -1 U.1 + 2 Q.4 <= 0
 r.23: - Q.3 - Q.4 - Y.1.2 <= -1
 r.24: + 5.6 U.1   -1 Z.2 + 72.8 Y.1.3 <= 56
 r.25:   -5.6 U.1 + 1 Z.2   -15.8 Y.1.3 <= 1
 r.26: -8 Y.1.3 + 1 U.1 <= 2
 r.27: Y.1.1 + Y.1.2 + Y.1.3 = 1 

Bounds
 0 <= Z.1 <= 1
 0 <= Z.2 <= 1
 0 <= U.1 <= 10
 0 <= Y.1.1 <= 1
 0 <= Q.1 <= 1
 0 <= Q.2 <= 1
 0 <= Y.1.2 <= 1
 0 <= Q.3 <= 1
 0 <= Q.4 <= 1
 0 <= Y.1.3 <= 1

Generals
 Z.1
 Z.2
 U.1

Integer
 Y.1.1
 Y.1.2
 Y.1.3
 Q.1
 Q.2
 Q.3
 Q.4

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


[Help-glpk] how to defne an array (something like pointer to pointer in C)

2009-05-11 Thread Maryam Ahmadi
Dear All,

I am new to glpk and MathProg. I am trying to model a problem in glpk
and solve it. The problem is that I don’t know how should I define the
following :
We have E[i] for each i that is member of N :
N is a set that contains A B C D E,
So, we have E[A], E[B], E[C], E[D], E[E]
The value for each of these members is as follows, for example:
E[A]:= AB
E[B] := AB BC
E[C] := BC CD
E[D] := CD DE
E[E] := DE
The problem is that I don’t know how to define E with the above specifications!

I have tested the followings and it didn’t work:
1)
param E:=
A AB;
B AB BC
C BC CD
D CD DE
E DE;

2)
param E :
if i==A
then AB
else if i==B
then AB BC
else if i==C
then BC CD
else if i==D
then CD DE
else if i==E
then DE;
3)
set EA; /*set of edges connected to node A*/
set EB; /*set of edges connected to node B*/
set EC; /*set of edges connected to node C*/
set ED; /*set of edges connected to node D*/
set EE; /*set of edges connected to node E*/
 set EA := AB;
set EB := AB BC;
set EC := BC CD;
set ED := CD DE;
set EE := DE;

and also we have:
u can be AB BC CD DE
and after defining the E, I have to check something like this:
for each I in N, for each u that is in E[i] ….some condition……

I really don’t know how should I solve this problem,how to define E,
and it is very essential to solve this problem..
Please do me a favor and help!
Many thanks in advance.
Regards


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


Re: [Help-glpk] how to defne an array (something like pointer to pointer in C)

2009-05-11 Thread xypron

Hello Maryam,

you could use the following formulation

set N;
set E{n in N};
display E;
data;
set N:= A B C D E;
set E[A]:= A AB;
set E[B]:= AB BC;
set E[C]:= BC CD;
set E[D]:= CD DE;
set E[E]:= DE;
end;

If you have large data sets consider using the table statement described in
doc\tables.pdf to read the data from a SQL database or from a CSV file.

Best regards

Xypron

Best regards

Xypron




Maryam Ahmadi wrote:
> 
> Dear All,
> 
> I am new to glpk and MathProg. I am trying to model a problem in glpk
> and solve it. The problem is that I don’t know how should I define the
> following :
> We have E[i] for each i that is member of N :
> N is a set that contains A B C D E,
> So, we have E[A], E[B], E[C], E[D], E[E]
> The value for each of these members is as follows, for example:
> E[A]:= AB
> E[B] := AB BC
> E[C] := BC CD
> E[D] := CD DE
> E[E] := DE
> The problem is that I don’t know how to define E with the above
> specifications!
> 
> I have tested the followings and it didn’t work:
> 1)
> param E:=
> A AB;
> B AB BC
> C BC CD
> D CD DE
> E DE;
> 
> 2)
> param E :
> if i==A
>   then AB
> else if i==B
>   then AB BC
> else if i==C
>   then BC CD
> else if i==D
>   then CD DE
> else if i==E
>   then DE;
> 3)
> set EA;   /*set of edges connected to node A*/
> set EB;   /*set of edges connected to node B*/
> set EC;   /*set of edges connected to node C*/
> set ED;   /*set of edges connected to node D*/
> set EE;   /*set of edges connected to node E*/
>  set EA := AB;
> set EB := AB BC;
> set EC := BC CD;
> set ED := CD DE;
> set EE := DE;
> 
> and also we have:
> u can be AB BC CD DE
> and after defining the E, I have to check something like this:
> for each I in N, for each u that is in E[i] ….some condition……
> 
> I really don’t know how should I solve this problem,how to define E,
> and it is very essential to solve this problem..
> Please do me a favor and help!
> Many thanks in advance.
> Regards
> 
> 
> ___
> Help-glpk mailing list
> Help-glpk@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-glpk
> 
> 

-- 
View this message in context: 
http://www.nabble.com/how-to-defne-an-array-%28something-like-pointer-to-pointer-in-C%29-tp23479009p23489985.html
Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com.



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


Re: [Help-glpk] Transforming a Piecewise Linear Functions in a Convex Predicate

2009-05-11 Thread Andrew Makhorin
> I need to transform a Piecewise Linear Functions in a Convex
> Predicate. In attachment there is a tex file with the function and my  
> transformation in a convex predicate. Using that convex predicate in a  
> milp, the milp does not found solution. So in attachment there is  
> my .c file with the function that create the MILP and an output with a  
> milp with random valute.
> The function in the examples is repeated two times, but it does not  
> matter.

> I don't know where is my mistake. It's impossible for me find it.

Below here is the output from glpsol (mip preprocessing is disabled,
debug output is enabled), which shows in details why your mip instance
has no integer feasible solution:

GLPSOL: GLPK LP/MIP Solver 4.39
Reading problem data from `milp.txt'...
27 rows, 10 columns, 69 non-zeros
10 integer variables, 9 of which are binary
59 lines were read
Scaling...
 A: min|aij| =  1.000e+00  max|aij| =  1.288e+02  ratio =  1.288e+02
GM: min|aij| =  5.546e-01  max|aij| =  1.803e+00  ratio =  3.252e+00
EQ: min|aij| =  3.161e-01  max|aij| =  1.000e+00  ratio =  3.163e+00
Crashing...
Size of triangular part = 27
glp_simplex: original LP has 27 rows, 10 columns, 69 non-zeros
glp_simplex: presolved LP has 21 rows, 10 columns, 52 non-zeros
Scaling...
 A: min|aij| =  1.000e+00  max|aij| =  1.288e+02  ratio =  1.288e+02
GM: min|aij| =  6.238e-01  max|aij| =  1.603e+00  ratio =  2.570e+00
EQ: min|aij| =  3.977e-01  max|aij| =  1.000e+00  ratio =  2.514e+00
Crashing...
Size of triangular part = 21
  0: obj =   0.0e+00  infeas =  4.684e+00 (0)
*10: obj =   1.0e+00  infeas =  4.926e-16 (0)
OPTIMAL SOLUTION FOUND
Integer optimization begins...

Processing node 1 at level 0
+10: mip = not found yet <=  +inf(1; 0)
Solving LP relaxation...
|10: obj =   1.0e+00  infeas =  0.000e+00 (0)
OPTIMAL SOLUTION FOUND
Found optimal solution to LP relaxation
Local bound is 1.0e+00
There are 6 fractional columns, integer infeasibility is 1.203e+00
branch_drtom: column 7 chosen to branch on
branch_drtom: down-branch bound is 1.0e+00
branch_drtom: up-branch   is infeasible
Up-branch is hopeless
+10: mip = not found yet <=   1.0e+00(1; 0)
Solving LP relaxation...
|11: obj =   1.0e+00  infeas =  0.000e+00 (0)
OPTIMAL SOLUTION FOUND
Found optimal solution to LP relaxation
Local bound is 1.0e+00
There are 3 fractional columns, integer infeasibility is 1.113e+00
branch_drtom: column 4 chosen to branch on
branch_drtom: down-branch bound is 1.0e+00
branch_drtom: up-branch   bound is 1.0e+00
Branching on column 4, primal value is 6.291208791e-01
Node 2 begins down branch, node 3 begins up branch 

Processing node 3 at level 1
+11: mip = not found yet <=   1.0e+00(2; 0)
Solving LP relaxation...
|12: obj =   1.0e+00  infeas =  0.000e+00 (0)
PROBLEM HAS NO FEASIBLE SOLUTION
LP relaxation has no feasible solution
Node 3 fathomed

Processing node 2 at level 1
+12: mip = not found yet <=   1.0e+00(1; 1)
Solving LP relaxation...
|15: obj =   1.0e+00  infeas =  0.000e+00 (0)
PROBLEM HAS NO FEASIBLE SOLUTION
LP relaxation has no feasible solution
Node 2 fathomed
Active list is empty!
+15: mip = not found yet <= tree is empty(0; 3)
PROBLEM HAS NO INTEGER FEASIBLE SOLUTION
Time used:   0.0 secs
Memory used: 0.1 Mb (57684 bytes)


I would suggest you to use the MathProg modeling language. It is
much easier than writing a model generator in C.

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


Andrew Makhorin



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


Re: [Help-glpk] how to defne an array (something like pointer to pointer in C)

2009-05-11 Thread Andrew Makhorin
> I am new to glpk and MathProg. I am trying to model a problem in glpk
> and solve it. The problem is that I don’t know how should I define the
> following :
> We have E[i] for each i that is member of N :
> N is a set that contains A B C D E,
> So, we have E[A], E[B], E[C], E[D], E[E]
> The value for each of these members is as follows, for example:
> E[A]:= AB
> E[B] := AB BC
> E[C] := BC CD
> E[D] := CD DE
> E[E] := DE
> The problem is that I don’t know how to define E with the above
>  specifications!

> I have tested the followings and it didn’t work:
> 1)
> param E:=
> A AB;
> B AB BC
> C BC CD
> D CD DE
> E DE;

> 2)
> param E :
> if i==A
>   then AB
> else if i==B
>   then AB BC
> else if i==C
>   then BC CD
> else if i==D
>   then CD DE
> else if i==E
>   then DE;
> 3)
> set EA;   /*set of edges connected to node A*/
> set EB;   /*set of edges connected to node B*/
> set EC;   /*set of edges connected to node C*/
> set ED;   /*set of edges connected to node D*/
> set EE;   /*set of edges connected to node E*/
>  set EA := AB;
> set EB := AB BC;
> set EC := BC CD;
> set ED := CD DE;
> set EE := DE;

> and also we have:
> u can be AB BC CD DE
> and after defining the E, I have to check something like this:
> for each I in N, for each u that is in E[i] ….some condition……

> I really don’t know how should I solve this problem,how to define E,
> and it is very essential to solve this problem..
> Please do me a favor and help!
> Many thanks in advance.

You may try something like this:

set N;
set E{i in N}, dimen 2;
display E;
data;
set N := A B C D E;
set E[A] := (A,B);
set E[B] := (A,B) (B,C);
set E[C] := (B,C) (C,D);
set E[D] := (C,D) (D,E);
set E[E] := (D,E);





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