lemon/mip_cplex.cc
author deba
Tue, 17 Oct 2006 10:50:57 +0000
changeset 2247 269a0dcee70b
parent 2219 c263168e0964
child 2253 1645f6cc9667
permissions -rw-r--r--
Update the Path concept
Concept check for paths

DirPath renamed to Path
The interface updated to the new lemon interface
Make difference between the empty path and the path from one node
Builder interface have not been changed
// I wanted but there was not accordance about it

UPath is removed
It was a buggy implementation, it could not iterate on the
nodes in the right order
Right way to use undirected paths => path of edges in undirected graphs

The tests have been modified to the current implementation
athos@2219
     1
/* -*- C++ -*-
athos@2219
     2
 *
athos@2219
     3
 * This file is a part of LEMON, a generic C++ optimization library
athos@2219
     4
 *
athos@2219
     5
 * Copyright (C) 2003-2006
athos@2219
     6
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
athos@2219
     7
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
athos@2219
     8
 *
athos@2219
     9
 * Permission to use, modify and distribute this software is granted
athos@2219
    10
 * provided that this copyright notice appears in all copies. For
athos@2219
    11
 * precise terms see the accompanying LICENSE file.
athos@2219
    12
 *
athos@2219
    13
 * This software is provided "AS IS" with no warranty of any kind,
athos@2219
    14
 * express or implied, and with no claim as to its suitability for any
athos@2219
    15
 * purpose.
athos@2219
    16
 *
athos@2219
    17
 */
athos@2219
    18
athos@2219
    19
#ifndef LEMON_MIP_CPLEX_CC
athos@2219
    20
#define LEMON_MIP_CPLEX_CC
athos@2219
    21
athos@2219
    22
///\file
athos@2219
    23
///\brief Implementation of the LEMON-CPLEX mip solver interface.
athos@2219
    24
athos@2219
    25
#include <lemon/mip_cplex.h>
athos@2219
    26
athos@2219
    27
namespace lemon {
athos@2219
    28
  
athos@2219
    29
  MipCplex::MipCplex() {
athos@2219
    30
    //This is unnecessary: setting integrality constraints on
athos@2219
    31
    //variables will set this, too 
athos@2219
    32
athos@2219
    33
    ///\todo The constant CPXPROB_MIP is
athos@2219
    34
    ///called CPXPROB_MILP in later versions
athos@2226
    35
#if CPX_VERSION < 800
athos@2219
    36
    CPXchgprobtype( env,  lp, CPXPROB_MIP);
athos@2226
    37
#else
athos@2226
    38
    CPXchgprobtype( env,  lp, CPXPROB_MILP);
athos@2226
    39
#endif
athos@2226
    40
athos@2219
    41
  }
athos@2219
    42
athos@2219
    43
  void MipCplex::_colType(int i, MipCplex::ColTypes col_type){
athos@2219
    44
athos@2219
    45
    // Note If a variable is to be changed to binary, a call to CPXchgbds
athos@2219
    46
    // should also be made to change the bounds to 0 and 1.
athos@2219
    47
athos@2219
    48
    int indices[1];
athos@2219
    49
    indices[0]=i;
athos@2219
    50
    char ctype[1];
athos@2219
    51
    switch (col_type){
athos@2219
    52
      case LEMON_INTEGER:
athos@2219
    53
	ctype[0]=CPX_INTEGER;//'I'
athos@2219
    54
	break;
athos@2219
    55
      case REAL:
athos@2219
    56
	ctype[0]=CPX_CONTINUOUS	;//'C'
athos@2219
    57
	break;
athos@2219
    58
    default:;
athos@2219
    59
        //FIXME problem
athos@2219
    60
    }
athos@2219
    61
    CPXchgctype (env, lp, 1, indices, ctype);
athos@2219
    62
  }
athos@2219
    63
  
athos@2219
    64
  MipCplex::ColTypes MipCplex::_colType(int i){
athos@2219
    65
    
athos@2219
    66
    char ctype[1];
athos@2219
    67
    status = CPXgetctype (env, lp, ctype, i, i);
athos@2219
    68
    switch (ctype[0]){
athos@2219
    69
athos@2219
    70
    case CPX_INTEGER:
athos@2219
    71
      return LEMON_INTEGER;
athos@2219
    72
    case CPX_CONTINUOUS:
athos@2219
    73
      return REAL;
athos@2219
    74
    default:
athos@2219
    75
      return REAL;//Error!
athos@2219
    76
    }
athos@2219
    77
athos@2219
    78
  }
athos@2219
    79
  
athos@2219
    80
  LpCplex::SolveExitStatus MipCplex::_solve(){
athos@2219
    81
athos@2219
    82
    status = CPXmipopt (env, lp);
athos@2219
    83
    if (status==0)
athos@2219
    84
      return SOLVED;
athos@2219
    85
    else
athos@2219
    86
      return UNSOLVED;
athos@2219
    87
athos@2219
    88
  }
athos@2219
    89
athos@2219
    90
athos@2219
    91
  LpCplex::SolutionStatus MipCplex::_getMipStatus(){
athos@2219
    92
athos@2219
    93
    int stat = CPXgetstat(env, lp);
athos@2219
    94
athos@2219
    95
    //Fortunately, MIP statuses did not change for cplex 8.0
athos@2219
    96
    switch (stat)
athos@2219
    97
    {
athos@2219
    98
      case CPXMIP_OPTIMAL:
athos@2219
    99
        return OPTIMAL;
athos@2219
   100
	//This also exists in later issues
athos@2219
   101
	//    case CPXMIP_UNBOUNDED:
athos@2219
   102
        //return INFINITE;
athos@2219
   103
      case CPXMIP_INFEASIBLE:
athos@2219
   104
        return INFEASIBLE;
athos@2219
   105
      default:
athos@2219
   106
        return UNDEFINED;
athos@2219
   107
    }
athos@2219
   108
    //Unboundedness not treated well: the following is from cplex 9.0 doc
athos@2219
   109
    // About Unboundedness
athos@2219
   110
athos@2219
   111
    // The treatment of models that are unbounded involves a few
athos@2219
   112
    // subtleties. Specifically, a declaration of unboundedness means that
athos@2219
   113
    // ILOG CPLEX has determined that the model has an unbounded
athos@2219
   114
    // ray. Given any feasible solution x with objective z, a multiple of
athos@2219
   115
    // the unbounded ray can be added to x to give a feasible solution
athos@2219
   116
    // with objective z-1 (or z+1 for maximization models). Thus, if a
athos@2219
   117
    // feasible solution exists, then the optimal objective is
athos@2219
   118
    // unbounded. Note that ILOG CPLEX has not necessarily concluded that
athos@2219
   119
    // a feasible solution exists. Users can call the routine CPXsolninfo
athos@2219
   120
    // to determine whether ILOG CPLEX has also concluded that the model
athos@2219
   121
    // has a feasible solution.
athos@2219
   122
      
athos@2219
   123
  }  
athos@2219
   124
athos@2219
   125
  MipCplex::Value MipCplex::_getPrimal(int i){
athos@2219
   126
    Value x;
athos@2219
   127
    CPXgetmipx(env, lp, &x, i, i);
athos@2219
   128
    return x;
athos@2219
   129
  }
athos@2219
   130
  
athos@2219
   131
  MipCplex::Value MipCplex::_getPrimalValue(){
athos@2219
   132
    Value objval;
athos@2219
   133
    status = CPXgetmipobjval(env, lp, &objval);
athos@2219
   134
    return objval;
athos@2219
   135
  }
athos@2219
   136
} //END OF NAMESPACE LEMON
athos@2219
   137
athos@2219
   138
#endif //END OF MIP_CPLEX_CC