src/test/lp_test.cc
author athos
Mon, 25 Apr 2005 15:43:11 +0000
changeset 1389 58b298e50c20
parent 1313 96b74270c3a1
child 1390 9c8e464ed940
permissions -rw-r--r--
Missing function _setRowBounds added to lp_skeleton.
ladanyi@1387
     1
#ifdef HAVE_CONFIG_H
ladanyi@1387
     2
#include <config.h>
ladanyi@1387
     3
#endif
ladanyi@1387
     4
ladanyi@1387
     5
#ifdef HAVE_GLPK
ladanyi@1387
     6
#include <lemon/lp_glpk.h>
ladanyi@1387
     7
#elif HAVE_CPLEX
ladanyi@1387
     8
#include <lemon/lp_cplex.h>
ladanyi@1387
     9
#endif
alpar@1254
    10
alpar@1254
    11
using namespace lemon;
alpar@1254
    12
ladanyi@1387
    13
#ifdef HAVE_GLPK
ladanyi@1387
    14
typedef LpGlpk LpDefault;
ladanyi@1387
    15
#elif HAVE_CPLEX
ladanyi@1387
    16
typedef LpCplex LpDefault;
ladanyi@1387
    17
#endif
ladanyi@1387
    18
alpar@1263
    19
void lpTest(LpSolverBase & lp)
alpar@1254
    20
{
alpar@1263
    21
  typedef LpSolverBase LP;
alpar@1256
    22
alpar@1309
    23
  std::vector<LP::Col> x(10);
alpar@1309
    24
  //  for(int i=0;i<10;i++) x.push_back(lp.addCol());
alpar@1309
    25
  lp.addColSet(x);
alpar@1256
    26
alpar@1256
    27
  std::vector<LP::Col> y(10);
alpar@1256
    28
  lp.addColSet(y);
alpar@1256
    29
alpar@1256
    30
  std::map<int,LP::Col> z;
alpar@1256
    31
  
alpar@1256
    32
  z.insert(std::make_pair(12,INVALID));
alpar@1256
    33
  z.insert(std::make_pair(2,INVALID));
alpar@1256
    34
  z.insert(std::make_pair(7,INVALID));
alpar@1256
    35
  z.insert(std::make_pair(5,INVALID));
alpar@1256
    36
  
alpar@1256
    37
  lp.addColSet(z);
alpar@1256
    38
alpar@1256
    39
alpar@1272
    40
  LP::Expr e,f,g;
alpar@1272
    41
  LP::Col p1,p2,p3,p4,p5;
alpar@1272
    42
  LP::Constr c;
alpar@1272
    43
  
alpar@1272
    44
  e[p1]=2;
alpar@1272
    45
  e.constComp()=12;
alpar@1272
    46
  e[p1]+=2;
alpar@1272
    47
  e.constComp()+=12;
alpar@1272
    48
  e[p1]-=2;
alpar@1272
    49
  e.constComp()-=12;
alpar@1272
    50
  
alpar@1272
    51
  e=2;
alpar@1272
    52
  e=2.2;
alpar@1272
    53
  e=p1;
alpar@1272
    54
  e=f;
alpar@1272
    55
alpar@1272
    56
  e+=2;
alpar@1272
    57
  e+=2.2;
alpar@1272
    58
  e+=p1;
alpar@1272
    59
  e+=f;
alpar@1272
    60
alpar@1272
    61
  e-=2;
alpar@1272
    62
  e-=2.2;
alpar@1272
    63
  e-=p1;
alpar@1272
    64
  e-=f;
alpar@1272
    65
alpar@1272
    66
  e*=2;
alpar@1272
    67
  e*=2.2;
alpar@1272
    68
  e/=2;
alpar@1272
    69
  e/=2.2;
alpar@1272
    70
alpar@1272
    71
  e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
alpar@1272
    72
      (f+12)+(12+f)+(p1+f)+(f+p1)+(f+g)+
alpar@1272
    73
      (f-12)+(12-f)+(p1-f)+(f-p1)+(f-g)+
alpar@1272
    74
      2.2*f+f*2.2+f/2.2+
alpar@1272
    75
      2*f+f*2+f/2+
alpar@1272
    76
      2.2*p1+p1*2.2+p1/2.2+
alpar@1272
    77
      2*p1+p1*2+p1/2
alpar@1272
    78
     );
alpar@1272
    79
  
alpar@1272
    80
alpar@1272
    81
  c = (e  <= f  );
alpar@1272
    82
  c = (e  <= 2.2);
alpar@1272
    83
  c = (e  <= 2  );
alpar@1272
    84
  c = (e  <= p1 );
alpar@1272
    85
  c = (2.2<= f  );
alpar@1272
    86
  c = (2  <= f  );
alpar@1272
    87
  c = (p1 <= f  );
alpar@1272
    88
  c = (p1 <= p2 );
alpar@1272
    89
  c = (p1 <= 2.2);
alpar@1272
    90
  c = (p1 <= 2  );
alpar@1272
    91
  c = (2.2<= p2 );
alpar@1272
    92
  c = (2  <= p2 );
alpar@1272
    93
alpar@1272
    94
  c = (e  >= f  );
alpar@1272
    95
  c = (e  >= 2.2);
alpar@1272
    96
  c = (e  >= 2  );
alpar@1272
    97
  c = (e  >= p1 );
alpar@1272
    98
  c = (2.2>= f  );
alpar@1272
    99
  c = (2  >= f  );
alpar@1272
   100
  c = (p1 >= f  );
alpar@1272
   101
  c = (p1 >= p2 );
alpar@1272
   102
  c = (p1 >= 2.2);
alpar@1272
   103
  c = (p1 >= 2  );
alpar@1272
   104
  c = (2.2>= p2 );
alpar@1272
   105
  c = (2  >= p2 );
alpar@1272
   106
alpar@1272
   107
  c = (e  == f  );
alpar@1272
   108
  c = (e  == 2.2);
alpar@1272
   109
  c = (e  == 2  );
alpar@1272
   110
  c = (e  == p1 );
alpar@1272
   111
  c = (2.2== f  );
alpar@1272
   112
  c = (2  == f  );
alpar@1272
   113
  c = (p1 == f  );
alpar@1272
   114
  //c = (p1 == p2 );
alpar@1272
   115
  c = (p1 == 2.2);
alpar@1272
   116
  c = (p1 == 2  );
alpar@1272
   117
  c = (2.2== p2 );
alpar@1272
   118
  c = (2  == p2 );
alpar@1272
   119
alpar@1272
   120
  c = (2 <= e <= 3);
alpar@1272
   121
  c = (2 <= p1<= 3);
alpar@1272
   122
alpar@1272
   123
  c = (2 >= e >= 3);
alpar@1272
   124
  c = (2 >= p1>= 3);
alpar@1272
   125
alpar@1256
   126
  e[x[3]]=2;
alpar@1256
   127
  e[x[3]]=4;
alpar@1256
   128
  e[x[3]]=1;
alpar@1256
   129
  e.constComp()=12;
alpar@1259
   130
  
alpar@1256
   131
  lp.addRow(LP::INF,e,23);
alpar@1259
   132
  lp.addRow(LP::INF,3.0*(x[1]+x[2]/2)-x[3],23);
alpar@1259
   133
  lp.addRow(LP::INF,3.0*(x[1]+x[2]*2-5*x[3]+12-x[4]/3)+2*x[4]-4,23);
alpar@1264
   134
alpar@1264
   135
  lp.addRow(x[1]+x[3]<=x[5]-3);
alpar@1264
   136
  lp.addRow(-7<=x[1]+x[3]-12<=3);
alpar@1273
   137
  lp.addRow(x[1]<=x[5]);
alpar@1272
   138
alpar@1263
   139
alpar@1264
   140
  
alpar@1264
   141
}
alpar@1264
   142
alpar@1263
   143
int main() 
alpar@1263
   144
{
ladanyi@1387
   145
  LpDefault lp;
alpar@1263
   146
ladanyi@1387
   147
  lpTest(lp);
alpar@1264
   148
alpar@1309
   149
  return 0;
alpar@1263
   150
}