src/test/lp_test.cc
author ladanyi
Mon, 18 Apr 2005 17:23:42 +0000
changeset 1369 f1cf6b807414
parent 1309 b3ce42a4d7d2
child 1387 37d1b20cd9ef
permissions -rw-r--r--
irrelevant changes
alpar@1313
     1
#include<lemon/lp_skeleton.h>
alpar@1309
     2
#include<lemon/lp_glpk.h>
alpar@1254
     3
alpar@1254
     4
using namespace lemon;
alpar@1254
     5
alpar@1263
     6
void lpTest(LpSolverBase & lp)
alpar@1254
     7
{
alpar@1263
     8
  typedef LpSolverBase LP;
alpar@1256
     9
alpar@1309
    10
  std::vector<LP::Col> x(10);
alpar@1309
    11
  //  for(int i=0;i<10;i++) x.push_back(lp.addCol());
alpar@1309
    12
  lp.addColSet(x);
alpar@1256
    13
alpar@1256
    14
  std::vector<LP::Col> y(10);
alpar@1256
    15
  lp.addColSet(y);
alpar@1256
    16
alpar@1256
    17
  std::map<int,LP::Col> z;
alpar@1256
    18
  
alpar@1256
    19
  z.insert(std::make_pair(12,INVALID));
alpar@1256
    20
  z.insert(std::make_pair(2,INVALID));
alpar@1256
    21
  z.insert(std::make_pair(7,INVALID));
alpar@1256
    22
  z.insert(std::make_pair(5,INVALID));
alpar@1256
    23
  
alpar@1256
    24
  lp.addColSet(z);
alpar@1256
    25
alpar@1256
    26
alpar@1272
    27
  LP::Expr e,f,g;
alpar@1272
    28
  LP::Col p1,p2,p3,p4,p5;
alpar@1272
    29
  LP::Constr c;
alpar@1272
    30
  
alpar@1272
    31
  e[p1]=2;
alpar@1272
    32
  e.constComp()=12;
alpar@1272
    33
  e[p1]+=2;
alpar@1272
    34
  e.constComp()+=12;
alpar@1272
    35
  e[p1]-=2;
alpar@1272
    36
  e.constComp()-=12;
alpar@1272
    37
  
alpar@1272
    38
  e=2;
alpar@1272
    39
  e=2.2;
alpar@1272
    40
  e=p1;
alpar@1272
    41
  e=f;
alpar@1272
    42
alpar@1272
    43
  e+=2;
alpar@1272
    44
  e+=2.2;
alpar@1272
    45
  e+=p1;
alpar@1272
    46
  e+=f;
alpar@1272
    47
alpar@1272
    48
  e-=2;
alpar@1272
    49
  e-=2.2;
alpar@1272
    50
  e-=p1;
alpar@1272
    51
  e-=f;
alpar@1272
    52
alpar@1272
    53
  e*=2;
alpar@1272
    54
  e*=2.2;
alpar@1272
    55
  e/=2;
alpar@1272
    56
  e/=2.2;
alpar@1272
    57
alpar@1272
    58
  e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
alpar@1272
    59
      (f+12)+(12+f)+(p1+f)+(f+p1)+(f+g)+
alpar@1272
    60
      (f-12)+(12-f)+(p1-f)+(f-p1)+(f-g)+
alpar@1272
    61
      2.2*f+f*2.2+f/2.2+
alpar@1272
    62
      2*f+f*2+f/2+
alpar@1272
    63
      2.2*p1+p1*2.2+p1/2.2+
alpar@1272
    64
      2*p1+p1*2+p1/2
alpar@1272
    65
     );
alpar@1272
    66
  
alpar@1272
    67
alpar@1272
    68
  c = (e  <= f  );
alpar@1272
    69
  c = (e  <= 2.2);
alpar@1272
    70
  c = (e  <= 2  );
alpar@1272
    71
  c = (e  <= p1 );
alpar@1272
    72
  c = (2.2<= f  );
alpar@1272
    73
  c = (2  <= f  );
alpar@1272
    74
  c = (p1 <= f  );
alpar@1272
    75
  c = (p1 <= p2 );
alpar@1272
    76
  c = (p1 <= 2.2);
alpar@1272
    77
  c = (p1 <= 2  );
alpar@1272
    78
  c = (2.2<= p2 );
alpar@1272
    79
  c = (2  <= p2 );
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 = (2 <= e <= 3);
alpar@1272
   108
  c = (2 <= p1<= 3);
alpar@1272
   109
alpar@1272
   110
  c = (2 >= e >= 3);
alpar@1272
   111
  c = (2 >= p1>= 3);
alpar@1272
   112
alpar@1256
   113
  e[x[3]]=2;
alpar@1256
   114
  e[x[3]]=4;
alpar@1256
   115
  e[x[3]]=1;
alpar@1256
   116
  e.constComp()=12;
alpar@1259
   117
  
alpar@1256
   118
  lp.addRow(LP::INF,e,23);
alpar@1259
   119
  lp.addRow(LP::INF,3.0*(x[1]+x[2]/2)-x[3],23);
alpar@1259
   120
  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
   121
alpar@1264
   122
  lp.addRow(x[1]+x[3]<=x[5]-3);
alpar@1264
   123
  lp.addRow(-7<=x[1]+x[3]-12<=3);
alpar@1273
   124
  lp.addRow(x[1]<=x[5]);
alpar@1272
   125
alpar@1263
   126
alpar@1264
   127
  
alpar@1264
   128
}
alpar@1264
   129
alpar@1263
   130
int main() 
alpar@1263
   131
{
alpar@1313
   132
  LpSkeleton lp_skel;
alpar@1263
   133
  LpGlpk lp_glpk;
alpar@1263
   134
alpar@1263
   135
  lpTest(lp_skel);
alpar@1263
   136
  lpTest(lp_glpk);
alpar@1264
   137
alpar@1309
   138
  return 0;
alpar@1263
   139
}