src/work/athos/lp/lp_glpk.cc
author alpar
Fri, 01 Apr 2005 19:50:29 +0000
changeset 1293 8ede2a6b2594
parent 1263 a490938ad0aa
child 1294 2dec219d9ca2
permissions -rw-r--r--
- Make lp stuff compilable
- Some 'set's removed
athos@1261
     1
/* -*- C++ -*-
athos@1261
     2
 * src/lemon/lp_glpk.cc - Part of LEMON, a generic C++ optimization library
athos@1261
     3
 *
athos@1261
     4
 * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
athos@1261
     5
 * (Egervary Combinatorial Optimization Research Group, EGRES).
athos@1261
     6
 *
athos@1261
     7
 * Permission to use, modify and distribute this software is granted
athos@1261
     8
 * provided that this copyright notice appears in all copies. For
athos@1261
     9
 * precise terms see the accompanying LICENSE file.
athos@1261
    10
 *
athos@1261
    11
 * This software is provided "AS IS" with no warranty of any kind,
athos@1261
    12
 * express or implied, and with no claim as to its suitability for any
athos@1261
    13
 * purpose.
athos@1261
    14
 *
athos@1261
    15
 */
athos@1261
    16
athos@1261
    17
#ifndef LEMON_LP_GLPK_CC
athos@1261
    18
#define LEMON_LP_GLPK_CC
athos@1261
    19
athos@1261
    20
///\file
athos@1261
    21
///\brief Implementation of the LEMON-GLPK lp solver interface.
athos@1261
    22
athos@1261
    23
#include "lp_glpk.h"
athos@1261
    24
athos@1261
    25
namespace lemon {
athos@1261
    26
athos@1261
    27
    /// \e
athos@1261
    28
    int LpGlpk::_addCol() { 
athos@1261
    29
	int i=lpx_add_cols(lp, 1);
athos@1261
    30
	_setColLowerBound(i, -INF);
athos@1261
    31
	_setColUpperBound(i, INF);
athos@1261
    32
	return i;
athos@1261
    33
    }
athos@1261
    34
athos@1261
    35
    /// \e
athos@1261
    36
    int LpGlpk::_addRow() { 
athos@1261
    37
	int i=lpx_add_rows(lp, 1);
athos@1261
    38
	return i;
athos@1261
    39
    }
athos@1261
    40
athos@1261
    41
  
athos@1261
    42
    void LpGlpk::_setRowCoeffs(int i, 
athos@1261
    43
			       int length,
alpar@1263
    44
			       const int   * indices, 
alpar@1263
    45
			       const Value   * values )
athos@1261
    46
    {
alpar@1263
    47
      lpx_set_mat_row(lp, i, length,
alpar@1263
    48
		      const_cast<int * >(indices) ,
alpar@1263
    49
		      const_cast<Value * >(values));
athos@1261
    50
    }
athos@1261
    51
  
athos@1261
    52
    void LpGlpk::_setColCoeffs(int i, 
athos@1261
    53
			       int length,
alpar@1263
    54
			       const int   * indices, 
alpar@1263
    55
			       const Value   * values)
athos@1261
    56
    {
alpar@1263
    57
      lpx_set_mat_col(lp, i, length,
alpar@1263
    58
		      const_cast<int * >(indices),
alpar@1263
    59
		      const_cast<Value * >(values));
athos@1261
    60
    }
athos@1261
    61
  
athos@1261
    62
    void LpGlpk::_setColLowerBound(int i, Value lo)
athos@1261
    63
    {
athos@1261
    64
      if (lo==INF) {
athos@1261
    65
	//FIXME error
athos@1261
    66
      }
athos@1261
    67
      int b=lpx_get_col_type(lp, i);
athos@1261
    68
      double up=lpx_get_col_ub(lp, i);	
athos@1261
    69
      if (lo==-INF) {
athos@1261
    70
	switch (b) {
athos@1261
    71
	case LPX_FR:
athos@1261
    72
	case LPX_LO:
athos@1261
    73
	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
athos@1261
    74
	  break;
athos@1261
    75
	case LPX_UP:
athos@1261
    76
	  break;
athos@1261
    77
	case LPX_DB:
athos@1261
    78
	case LPX_FX:
athos@1261
    79
	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
athos@1261
    80
	  break;
athos@1261
    81
	default: ;
athos@1261
    82
	  //FIXME error
athos@1261
    83
	}
athos@1261
    84
      } else {
athos@1261
    85
	switch (b) {
athos@1261
    86
	case LPX_FR:
athos@1261
    87
	case LPX_LO:
athos@1261
    88
	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
athos@1261
    89
	  break;
athos@1261
    90
	case LPX_UP:	  
athos@1261
    91
	case LPX_DB:
athos@1261
    92
	case LPX_FX:
athos@1261
    93
	  if (lo==up) 
athos@1261
    94
	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
athos@1261
    95
	  else 
athos@1261
    96
	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
athos@1261
    97
	  break;
athos@1261
    98
	default: ;
athos@1261
    99
	  //FIXME error
athos@1261
   100
	}
athos@1261
   101
      }
athos@1261
   102
athos@1261
   103
    }
athos@1261
   104
  
athos@1261
   105
    void LpGlpk::_setColUpperBound(int i, Value up)
athos@1261
   106
    {
athos@1261
   107
      if (up==-INF) {
athos@1261
   108
	//FIXME error
athos@1261
   109
      }
athos@1261
   110
      int b=lpx_get_col_type(lp, i);
athos@1261
   111
      double lo=lpx_get_col_lb(lp, i);
athos@1261
   112
      if (up==INF) {
athos@1261
   113
	switch (b) {
athos@1261
   114
	case LPX_FR:
athos@1261
   115
	case LPX_LO:
athos@1261
   116
	  break;
athos@1261
   117
	case LPX_UP:
athos@1261
   118
	  lpx_set_col_bnds(lp, i, LPX_FR, lo, up);
athos@1261
   119
	  break;
athos@1261
   120
	case LPX_DB:
athos@1261
   121
	case LPX_FX:
athos@1261
   122
	  lpx_set_col_bnds(lp, i, LPX_LO, lo, up);
athos@1261
   123
	  break;
athos@1261
   124
	default: ;
athos@1261
   125
	  //FIXME error
athos@1261
   126
	}
athos@1261
   127
      } else {
athos@1261
   128
	switch (b) {
athos@1261
   129
	case LPX_FR:
athos@1261
   130
	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
athos@1261
   131
	  break;
athos@1261
   132
	case LPX_UP:
athos@1261
   133
	  lpx_set_col_bnds(lp, i, LPX_UP, lo, up);
athos@1261
   134
	  break;
athos@1261
   135
	case LPX_LO:
athos@1261
   136
	case LPX_DB:
athos@1261
   137
	case LPX_FX:
athos@1261
   138
	  if (lo==up) 
athos@1261
   139
	    lpx_set_col_bnds(lp, i, LPX_FX, lo, up);
athos@1261
   140
	  else 
athos@1261
   141
	    lpx_set_col_bnds(lp, i, LPX_DB, lo, up);
athos@1261
   142
	  break;
athos@1261
   143
	default: ;
athos@1261
   144
	  //FIXME error
athos@1261
   145
	}
athos@1261
   146
      }
athos@1261
   147
    }
athos@1261
   148
  
athos@1261
   149
    void LpGlpk::_setRowLowerBound(int i, Value lo)
athos@1261
   150
    {
athos@1261
   151
      if (lo==INF) {
athos@1261
   152
	//FIXME error
athos@1261
   153
      }
athos@1261
   154
      int b=lpx_get_row_type(lp, i);
athos@1261
   155
      double up=lpx_get_row_ub(lp, i);	
athos@1261
   156
      if (lo==-INF) {
athos@1261
   157
	switch (b) {
athos@1261
   158
	case LPX_FR:
athos@1261
   159
	case LPX_LO:
athos@1261
   160
	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
athos@1261
   161
	  break;
athos@1261
   162
	case LPX_UP:
athos@1261
   163
	  break;
athos@1261
   164
	case LPX_DB:
athos@1261
   165
	case LPX_FX:
athos@1261
   166
	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1261
   167
	  break;
athos@1261
   168
	default: ;
athos@1261
   169
	  //FIXME error
athos@1261
   170
	}
athos@1261
   171
      } else {
athos@1261
   172
	switch (b) {
athos@1261
   173
	case LPX_FR:
athos@1261
   174
	case LPX_LO:
athos@1261
   175
	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
athos@1261
   176
	  break;
athos@1261
   177
	case LPX_UP:	  
athos@1261
   178
	case LPX_DB:
athos@1261
   179
	case LPX_FX:
athos@1261
   180
	  if (lo==up) 
athos@1261
   181
	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
athos@1261
   182
	  else 
athos@1261
   183
	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
athos@1261
   184
	  break;
athos@1261
   185
	default: ;
athos@1261
   186
	  //FIXME error
athos@1261
   187
	}
athos@1261
   188
      }
athos@1261
   189
    }
athos@1261
   190
  
athos@1261
   191
    void LpGlpk::_setRowUpperBound(int i, Value up)
athos@1261
   192
    {
athos@1261
   193
      if (up==-INF) {
athos@1261
   194
	//FIXME error
athos@1261
   195
      }
athos@1261
   196
      int b=lpx_get_row_type(lp, i);
athos@1261
   197
      double lo=lpx_get_row_lb(lp, i);
athos@1261
   198
      if (up==INF) {
athos@1261
   199
	switch (b) {
athos@1261
   200
	case LPX_FR:
athos@1261
   201
	case LPX_LO:
athos@1261
   202
	  break;
athos@1261
   203
	case LPX_UP:
athos@1261
   204
	  lpx_set_row_bnds(lp, i, LPX_FR, lo, up);
athos@1261
   205
	  break;
athos@1261
   206
	case LPX_DB:
athos@1261
   207
	case LPX_FX:
athos@1261
   208
	  lpx_set_row_bnds(lp, i, LPX_LO, lo, up);
athos@1261
   209
	  break;
athos@1261
   210
	default: ;
athos@1261
   211
	  //FIXME error
athos@1261
   212
	}
athos@1261
   213
      } else {
athos@1261
   214
	switch (b) {
athos@1261
   215
	case LPX_FR:
athos@1261
   216
	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1261
   217
	  break;
athos@1261
   218
	case LPX_UP:
athos@1261
   219
	  lpx_set_row_bnds(lp, i, LPX_UP, lo, up);
athos@1261
   220
	  break;
athos@1261
   221
	case LPX_LO:
athos@1261
   222
	case LPX_DB:
athos@1261
   223
	case LPX_FX:
athos@1261
   224
	  if (lo==up) 
athos@1261
   225
	    lpx_set_row_bnds(lp, i, LPX_FX, lo, up);
athos@1261
   226
	  else 
athos@1261
   227
	    lpx_set_row_bnds(lp, i, LPX_DB, lo, up);
athos@1261
   228
	  break;
athos@1261
   229
	default: ;
athos@1261
   230
	  //FIXME error
athos@1261
   231
	}
athos@1261
   232
      }
athos@1261
   233
    }
athos@1261
   234
  
athos@1261
   235
    void LpGlpk::_setObjCoeff(int i, Value obj_coef)
athos@1261
   236
    {
athos@1261
   237
      lpx_set_obj_coef(lp, i, obj_coef);
athos@1261
   238
    }
athos@1261
   239
alpar@1263
   240
alpar@1293
   241
  LpGlpk::SolutionStatus LpGlpk::_solve()
alpar@1263
   242
  {
alpar@1293
   243
    return SOLVED;
alpar@1263
   244
  }
alpar@1263
   245
alpar@1293
   246
  LpGlpk::Value LpGlpk::_getPrimal(int i)
alpar@1263
   247
  {
alpar@1263
   248
    return 0;
alpar@1263
   249
  }
alpar@1263
   250
  
alpar@1263
   251
alpar@1263
   252
athos@1261
   253
} //END OF NAMESPACE LEMON
athos@1261
   254
athos@1261
   255
#endif //LEMON_LP_GLPK_CC