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