test/lp_test.cc
author alpar
Thu, 09 Jun 2005 09:49:56 +0000
changeset 1459 2ee881cf30a8
parent 1437 2a3f3448ced1
child 1473 876c7b7f4dae
permissions -rw-r--r--
- InDegMap fixed
- OutDegMap added
- test cases added for them both
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@1445
    37
  {
alpar@1445
    38
    LP::Expr e,f,g;
alpar@1445
    39
    LP::Col p1,p2,p3,p4,p5;
alpar@1445
    40
    LP::Constr c;
alpar@1445
    41
    
alpar@1445
    42
    e[p1]=2;
alpar@1445
    43
    e.constComp()=12;
alpar@1445
    44
    e[p1]+=2;
alpar@1445
    45
    e.constComp()+=12;
alpar@1445
    46
    e[p1]-=2;
alpar@1445
    47
    e.constComp()-=12;
alpar@1445
    48
    
alpar@1445
    49
    e=2;
alpar@1445
    50
    e=2.2;
alpar@1445
    51
    e=p1;
alpar@1445
    52
    e=f;
alpar@1445
    53
    
alpar@1445
    54
    e+=2;
alpar@1445
    55
    e+=2.2;
alpar@1445
    56
    e+=p1;
alpar@1445
    57
    e+=f;
alpar@1445
    58
    
alpar@1445
    59
    e-=2;
alpar@1445
    60
    e-=2.2;
alpar@1445
    61
    e-=p1;
alpar@1445
    62
    e-=f;
alpar@1445
    63
    
alpar@1445
    64
    e*=2;
alpar@1445
    65
    e*=2.2;
alpar@1445
    66
    e/=2;
alpar@1445
    67
    e/=2.2;
alpar@1445
    68
    
alpar@1445
    69
    e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
alpar@1445
    70
       (f+12)+(12+f)+(p1+f)+(f+p1)+(f+g)+
alpar@1445
    71
       (f-12)+(12-f)+(p1-f)+(f-p1)+(f-g)+
alpar@1445
    72
       2.2*f+f*2.2+f/2.2+
alpar@1445
    73
       2*f+f*2+f/2+
alpar@1445
    74
       2.2*p1+p1*2.2+p1/2.2+
alpar@1445
    75
       2*p1+p1*2+p1/2
alpar@1445
    76
       );
alpar@1256
    77
alpar@1445
    78
alpar@1445
    79
    c = (e  <= f  );
alpar@1445
    80
    c = (e  <= 2.2);
alpar@1445
    81
    c = (e  <= 2  );
alpar@1445
    82
    c = (e  <= p1 );
alpar@1445
    83
    c = (2.2<= f  );
alpar@1445
    84
    c = (2  <= f  );
alpar@1445
    85
    c = (p1 <= f  );
alpar@1445
    86
    c = (p1 <= p2 );
alpar@1445
    87
    c = (p1 <= 2.2);
alpar@1445
    88
    c = (p1 <= 2  );
alpar@1445
    89
    c = (2.2<= p2 );
alpar@1445
    90
    c = (2  <= p2 );
alpar@1445
    91
    
alpar@1445
    92
    c = (e  >= f  );
alpar@1445
    93
    c = (e  >= 2.2);
alpar@1445
    94
    c = (e  >= 2  );
alpar@1445
    95
    c = (e  >= p1 );
alpar@1445
    96
    c = (2.2>= f  );
alpar@1445
    97
    c = (2  >= f  );
alpar@1445
    98
    c = (p1 >= f  );
alpar@1445
    99
    c = (p1 >= p2 );
alpar@1445
   100
    c = (p1 >= 2.2);
alpar@1445
   101
    c = (p1 >= 2  );
alpar@1445
   102
    c = (2.2>= p2 );
alpar@1445
   103
    c = (2  >= p2 );
alpar@1445
   104
    
alpar@1445
   105
    c = (e  == f  );
alpar@1445
   106
    c = (e  == 2.2);
alpar@1445
   107
    c = (e  == 2  );
alpar@1445
   108
    c = (e  == p1 );
alpar@1445
   109
    c = (2.2== f  );
alpar@1445
   110
    c = (2  == f  );
alpar@1445
   111
    c = (p1 == f  );
alpar@1445
   112
    //c = (p1 == p2 );
alpar@1445
   113
    c = (p1 == 2.2);
alpar@1445
   114
    c = (p1 == 2  );
alpar@1445
   115
    c = (2.2== p2 );
alpar@1445
   116
    c = (2  == p2 );
alpar@1445
   117
    
alpar@1445
   118
    c = (2 <= e <= 3);
alpar@1445
   119
    c = (2 <= p1<= 3);
alpar@1445
   120
    
alpar@1445
   121
    c = (2 >= e >= 3);
alpar@1445
   122
    c = (2 >= p1>= 3);
alpar@1445
   123
    
alpar@1445
   124
    e[x[3]]=2;
alpar@1445
   125
    e[x[3]]=4;
alpar@1445
   126
    e[x[3]]=1;
alpar@1445
   127
    e.constComp()=12;
alpar@1445
   128
    
alpar@1445
   129
    lp.addRow(LP::INF,e,23);
alpar@1445
   130
    lp.addRow(LP::INF,3.0*(x[1]+x[2]/2)-x[3],23);
alpar@1445
   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@1445
   132
    
alpar@1445
   133
    lp.addRow(x[1]+x[3]<=x[5]-3);
alpar@1445
   134
    lp.addRow(-7<=x[1]+x[3]-12<=3);
alpar@1445
   135
    lp.addRow(x[1]<=x[5]);
alpar@1445
   136
  }
alpar@1272
   137
  
alpar@1445
   138
  {
alpar@1445
   139
    LP::DualExpr e,f,g;
alpar@1445
   140
    LP::Row p1,p2,p3,p4,p5;
alpar@1445
   141
    
alpar@1445
   142
    e[p1]=2;
alpar@1445
   143
    e[p1]+=2;
alpar@1445
   144
    e[p1]-=2;
alpar@1445
   145
    
alpar@1445
   146
    e=p1;
alpar@1445
   147
    e=f;
alpar@1445
   148
    
alpar@1445
   149
    e+=p1;
alpar@1445
   150
    e+=f;
alpar@1445
   151
    
alpar@1445
   152
    e-=p1;
alpar@1445
   153
    e-=f;
alpar@1445
   154
    
alpar@1445
   155
    e*=2;
alpar@1445
   156
    e*=2.2;
alpar@1445
   157
    e/=2;
alpar@1445
   158
    e/=2.2;
alpar@1445
   159
    
alpar@1445
   160
    e=((p1+p2)+(p1-p2)+(p1+12)+(12+p1)+(p1-12)+(12-p1)+
alpar@1445
   161
       (p1+f)+(f+p1)+(f+g)+
alpar@1445
   162
       (p1-f)+(f-p1)+(f-g)+
alpar@1445
   163
       2.2*f+f*2.2+f/2.2+
alpar@1445
   164
       2*f+f*2+f/2+
alpar@1445
   165
       2.2*p1+p1*2.2+p1/2.2+
alpar@1445
   166
       2*p1+p1*2+p1/2
alpar@1445
   167
       );
alpar@1445
   168
  }
alpar@1272
   169
  
alpar@1272
   170
alpar@1264
   171
}
alpar@1264
   172
alpar@1263
   173
int main() 
alpar@1263
   174
{
alpar@1390
   175
  LpSkeleton lp_skel;
alpar@1390
   176
  lpTest(lp_skel);
alpar@1390
   177
ladanyi@1437
   178
#ifdef HAVE_GLPK
ladanyi@1437
   179
  LpGlpk lp_glpk;
ladanyi@1437
   180
  lpTest(lp_glpk);
ladanyi@1437
   181
#endif
alpar@1263
   182
ladanyi@1437
   183
#ifdef HAVE_CPLEX
ladanyi@1437
   184
//  LpCplex lp_cplex;
ladanyi@1437
   185
//  lpTest(lp_cplex);
ladanyi@1437
   186
#endif
alpar@1264
   187
alpar@1309
   188
  return 0;
alpar@1263
   189
}