help-glpk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] Beginners problems: Using MathProg and GLPK


From: Sebastian Küpper
Subject: [Help-glpk] Beginners problems: Using MathProg and GLPK
Date: Fri, 09 Jul 2010 11:09:08 +0200

Hi,

I try to use GLPK using Dev C++ and the MathProg modelling language. I'm trying 
to model a graph problem and I generated this MathProg file:

# sets
set Ys :=  1  2  3  4  5  6 ;
set Gueter := 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19 
 20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39 
 40  41  42 ;
set Knoten := 1  2  3  4  5  6  7 ;
# Parameters
#Decision variables
var y {i in Ys} >= 0;
var ZSources {i in Gueter} >= 0;
var ZTargets {i in Gueter} <= 0;
var Z {a in Knoten, i in Gueter}
# Objective function
minimize g: (sum{i in Ys} Ys[i]) - (sum{j in Gueter} ZSources[j]-ZTargets[j])
#Constraints:
y[1]-Z[1, 1]+z[1, 2] >=0;
y[1]+Z[1, 1]-z[1, 2] >=0;
y[2]-Z[2, 3]+z[2, 2] >=0;
y[2]+Z[2, 3]-z[2, 2] >=0;
y[3]-Z[3, 4]+z[3, 1] >=0;
y[3]+Z[3, 4]-z[3, 1] >=0;
y[4]-Z[4, 5]+z[4, 1] >=0;
y[4]+Z[4, 5]-z[4, 1] >=0;
y[5]-Z[5, 6]+z[5, 3] >=0;
y[5]+Z[5, 6]-z[5, 3] >=0;
y[6]-Z[6, 7]+z[6, 3] >=0;
y[6]+Z[6, 7]-z[6, 3] >=0;
Z[1,1] = ZSources[1];
Z[2,1] = ZSources[2];
Z[3,1] = ZSources[3];
Z[4,1] = ZSources[4];
Z[5,1] = ZSources[5];
Z[6,1] = ZSources[6];
Z[7,2] = ZSources[7];
Z[8,2] = ZSources[8];
Z[9,2] = ZSources[9];
Z[10,2] = ZSources[10];
Z[11,2] = ZSources[11];
Z[12,2] = ZSources[12];
Z[13,3] = ZSources[13];
Z[14,3] = ZSources[14];
Z[15,3] = ZSources[15];
Z[16,3] = ZSources[16];
Z[17,3] = ZSources[17];
Z[18,3] = ZSources[18];
Z[19,4] = ZSources[19];
Z[20,4] = ZSources[20];
Z[21,4] = ZSources[21];
Z[22,4] = ZSources[22];
Z[23,4] = ZSources[23];
Z[24,4] = ZSources[24];
Z[25,5] = ZSources[25];
Z[26,5] = ZSources[26];
Z[27,5] = ZSources[27];
Z[28,5] = ZSources[28];
Z[29,5] = ZSources[29];
Z[30,5] = ZSources[30];
Z[31,6] = ZSources[31];
Z[32,6] = ZSources[32];
Z[33,6] = ZSources[33];
Z[34,6] = ZSources[34];
Z[35,6] = ZSources[35];
Z[36,6] = ZSources[36];
Z[37,7] = ZSources[37];
Z[38,7] = ZSources[38];
Z[39,7] = ZSources[39];
Z[40,7] = ZSources[40];
Z[41,7] = ZSources[41];
Z[42,7] = ZSources[42];
Z[1,1] = ZTargets[1];
Z[2,2] = ZTargets[2];
Z[3,3] = ZTargets[3];
Z[4,4] = ZTargets[4];
Z[5,5] = ZTargets[5];
Z[6,6] = ZTargets[6];
Z[7,2] = ZTargets[7];
Z[8,2] = ZTargets[8];
Z[9,3] = ZTargets[9];
Z[10,4] = ZTargets[10];
Z[11,5] = ZTargets[11];
Z[12,6] = ZTargets[12];
Z[13,2] = ZTargets[13];
Z[14,3] = ZTargets[14];
Z[15,3] = ZTargets[15];
Z[16,4] = ZTargets[16];
Z[17,5] = ZTargets[17];
Z[18,6] = ZTargets[18];
Z[19,2] = ZTargets[19];
Z[20,3] = ZTargets[20];
Z[21,4] = ZTargets[21];
Z[22,4] = ZTargets[22];
Z[23,5] = ZTargets[23];
Z[24,6] = ZTargets[24];
Z[25,2] = ZTargets[25];
Z[26,3] = ZTargets[26];
Z[27,4] = ZTargets[27];
Z[28,5] = ZTargets[28];
Z[29,5] = ZTargets[29];
Z[30,6] = ZTargets[30];
Z[31,2] = ZTargets[31];
Z[32,3] = ZTargets[32];
Z[33,4] = ZTargets[33];
Z[34,5] = ZTargets[34];
Z[35,6] = ZTargets[35];
Z[36,6] = ZTargets[36];
Z[37,2] = ZTargets[37];
Z[38,3] = ZTargets[38];
Z[39,4] = ZTargets[39];
Z[40,5] = ZTargets[40];
Z[41,6] = ZTargets[41];
Z[42,7] = ZTargets[42];

using this C++ code:
     ofstream file;
     file.open("testausgabe.txt");
     file << "# sets" << endl;
     file << "set Ys := ";
     for(int i = 1; i<=g->m(); ++i) file << " " << i << " ";
     file << ";" << endl;
     file << "set Gueter :=";
     for(int i = 0; i<g->n(); ++i)
        for(int j = 1; j < g->n(); ++j)
           file << " " << (i*(g->n()-1)+j) << " ";
     file << ";" << endl;
     file << "set Knoten :=" ;
     for(int i = 1; i<=g->n(); ++i) file << " " << i << " ";
     file << ";" << endl;
     file << "# Parameters" << endl;
     file << "#Decision variables" << endl;
     file << "var y {i in Ys} >= 0;" << endl;
     file << "var ZSources {i in Gueter} >= 0;" << endl;
     file << "var ZTargets {i in Gueter} <= 0;" << endl;
     file << "var Z {a in Knoten, i in Gueter}" << endl;
     file << "# Objective function" << endl;
     file << "minimize g: (sum{i in Ys} Ys[i]) - (sum{j in Gueter} 
ZSources[j]-ZTargets[j])" << endl;
     file << "#Constraints:" << endl;
     for(int i=0; i<g->m(); ++i){
             int j= ((g->indexVonKnoten(g->getEdges().at(i).target))+1);
             int k= ((g->indexVonKnoten(g->getEdges().at(i).source))+1);
             file << "y[" << (i+1) << "]-Z[" << (i+1) <<  ", " << j << "]+z[" 
<< (i+1) <<  ", " << k << "] >=0;"<< endl;
             file << "y[" << (i+1) << "]+Z[" << (i+1) <<  ", " << j << "]-z[" 
<< (i+1) <<  ", " << k << "] >=0;"<< endl;
     };
     for(int i=0; i<g->n(); ++i){ // gehe alle Knoten als Quelleknoten durch
         for(int j=0; j<g->n()-1; ++j){ // gehe die Güter durch, die Knoten i 
als Quellknoten haben
             file << "Z[" << (i*(g->n()-1)+j+1) << "," << (i+1) << "] = 
ZSources[" << (i*(g->n()-1)+j+1) <<"];"<< endl;
         };
     };
     for(int i=0; i<g->n(); ++i){ // gehe alle Knoten als Quelleknoten durch
         for(int j=0; j<g->n()-1; ++j){ // gehe die Güter durch, die Knoten i 
als Quellknoten haben
             file << "Z[" << (i*(g->n()-1)+j+1) << "," << ((j>=i)?(j+1):(j+2)) 
<< "] = ZTargets[" << (i*(g->n()-1)+j+1) <<"];"<< endl;
         };
     };
     file.close();


GLPK doesn't accept this file because of the line "set Ys :=  1  2  3  4  5  6 
;". Why is this so and how can I fix this? Many thanks in advance :).

Greetings,
Sebastian
-- 
GMX DSL: Internet-, Telefon- und Handy-Flat ab 19,99 EUR/mtl.  
Bis zu 150 EUR Startguthaben inklusive! http://portal.gmx.net/de/go/dsl

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01



reply via email to

[Prev in Thread] Current Thread [Next in Thread]