[Lemon-commits] [lemon_svn] athos: r2954 - hugo/trunk/lemon

Lemon SVN svn at lemon.cs.elte.hu
Mon Nov 6 21:51:27 CET 2006


Author: athos
Date: Mon Sep 25 10:50:36 2006
New Revision: 2954

Added:
   hugo/trunk/lemon/mip_cplex.cc
   hugo/trunk/lemon/mip_cplex.cc~
   hugo/trunk/lemon/mip_cplex.h
   hugo/trunk/lemon/mip_cplex.h~

Log:
Missing cplex files: sorry.

Added: hugo/trunk/lemon/mip_cplex.cc
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/mip_cplex.cc	Mon Sep 25 10:50:36 2006
@@ -0,0 +1,133 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_MIP_CPLEX_CC
+#define LEMON_MIP_CPLEX_CC
+
+///\file
+///\brief Implementation of the LEMON-CPLEX mip solver interface.
+
+#include <lemon/mip_cplex.h>
+
+namespace lemon {
+  
+  MipCplex::MipCplex() {
+    //This is unnecessary: setting integrality constraints on
+    //variables will set this, too 
+
+    ///\todo The constant CPXPROB_MIP is
+    ///called CPXPROB_MILP in later versions
+    CPXchgprobtype( env,  lp, CPXPROB_MIP);
+  }
+
+  void MipCplex::_colType(int i, MipCplex::ColTypes col_type){
+
+    // Note If a variable is to be changed to binary, a call to CPXchgbds
+    // should also be made to change the bounds to 0 and 1.
+
+    int indices[1];
+    indices[0]=i;
+    char ctype[1];
+    switch (col_type){
+      case LEMON_INTEGER:
+	ctype[0]=CPX_INTEGER;//'I'
+	break;
+      case REAL:
+	ctype[0]=CPX_CONTINUOUS	;//'C'
+	break;
+    default:;
+        //FIXME problem
+    }
+    CPXchgctype (env, lp, 1, indices, ctype);
+  }
+  
+  MipCplex::ColTypes MipCplex::_colType(int i){
+    
+    char ctype[1];
+    status = CPXgetctype (env, lp, ctype, i, i);
+    switch (ctype[0]){
+
+    case CPX_INTEGER:
+      return LEMON_INTEGER;
+    case CPX_CONTINUOUS:
+      return REAL;
+    default:
+      return REAL;//Error!
+    }
+
+  }
+  
+  LpCplex::SolveExitStatus MipCplex::_solve(){
+
+    status = CPXmipopt (env, lp);
+    if (status==0)
+      return SOLVED;
+    else
+      return UNSOLVED;
+
+  }
+
+
+  LpCplex::SolutionStatus MipCplex::_getMipStatus(){
+
+    int stat = CPXgetstat(env, lp);
+
+    //Fortunately, MIP statuses did not change for cplex 8.0
+    switch (stat)
+    {
+      case CPXMIP_OPTIMAL:
+        return OPTIMAL;
+	//This also exists in later issues
+	//    case CPXMIP_UNBOUNDED:
+        //return INFINITE;
+      case CPXMIP_INFEASIBLE:
+        return INFEASIBLE;
+      default:
+        return UNDEFINED;
+    }
+    //Unboundedness not treated well: the following is from cplex 9.0 doc
+    // About Unboundedness
+
+    // The treatment of models that are unbounded involves a few
+    // subtleties. Specifically, a declaration of unboundedness means that
+    // ILOG CPLEX has determined that the model has an unbounded
+    // ray. Given any feasible solution x with objective z, a multiple of
+    // the unbounded ray can be added to x to give a feasible solution
+    // with objective z-1 (or z+1 for maximization models). Thus, if a
+    // feasible solution exists, then the optimal objective is
+    // unbounded. Note that ILOG CPLEX has not necessarily concluded that
+    // a feasible solution exists. Users can call the routine CPXsolninfo
+    // to determine whether ILOG CPLEX has also concluded that the model
+    // has a feasible solution.
+      
+  }  
+
+  MipCplex::Value MipCplex::_getPrimal(int i){
+    Value x;
+    CPXgetmipx(env, lp, &x, i, i);
+    return x;
+  }
+  
+  MipCplex::Value MipCplex::_getPrimalValue(){
+    Value objval;
+    status = CPXgetmipobjval(env, lp, &objval);
+    return objval;
+  }
+} //END OF NAMESPACE LEMON
+
+#endif //END OF MIP_CPLEX_CC

Added: hugo/trunk/lemon/mip_cplex.cc~
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/mip_cplex.cc~	Mon Sep 25 10:50:36 2006
@@ -0,0 +1,135 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_MIP_CPLEX_CC
+#define LEMON_MIP_CPLEX_CC
+
+///\file
+///\brief Implementation of the LEMON-CPLEX mip solver interface.
+
+#include <lemon/mip_cplex.h>
+
+namespace lemon {
+  
+  MipCplex::MipCplex() {
+    //This is unnecessary: setting integrality constraints on
+    //variables will set this, too 
+
+    ///\todo The constant CPXPROB_MIP is
+    ///called CPXPROB_MILP in later versions
+    CPXchgprobtype( env,  lp, CPXPROB_MIP);
+  }
+
+  void MipCplex::_colType(int i, MipCplex::ColTypes col_type){
+
+    // Note If a variable is to be changed to binary, a call to CPXchgbds
+    // should also be made to change the bounds to 0 and 1.
+
+    int indices[1];
+    indices[0]=i;
+    char ctype[1];
+    switch (col_type){
+      case INTEGER:
+	ctype[0]=CPX_INTEGER;//'I'
+	break;
+      case REAL:
+	ctype[0]=CPX_CONTINUOUS	;//'C'
+	break;
+    default:;
+        //FIXME problem
+    }
+    CPXchgctype (env, lp, 1, indices, ctype);
+  }
+  
+  MipCplex::ColTypes MipCplex::_colType(int i){
+    
+    char ctype[1];
+    status = CPXgetctype (env, lp, ctype, i, i);
+    std::cout<<"Kukucska: "<<INTEGER<<std::endl;
+    return REAL;
+//     switch (ctype[0]){
+
+//     case CPX_INTEGER:
+//       return INTEGER;
+//     case CPX_CONTINUOUS:
+//       return REAL;
+//     default:
+//       return REAL;//Error!
+//     }
+
+  }
+  
+  LpCplex::SolveExitStatus MipCplex::_solve(){
+
+    status = CPXmipopt (env, lp);
+    if (status==0)
+      return SOLVED;
+    else
+      return UNSOLVED;
+
+  }
+
+
+  LpCplex::SolutionStatus MipCplex::_getMipStatus(){
+
+    int stat = CPXgetstat(env, lp);
+
+    //Fortunately, MIP statuses did not change for cplex 8.0
+    switch (stat)
+    {
+      case CPXMIP_OPTIMAL:
+        return OPTIMAL;
+	//This also exists in later issues
+	//    case CPXMIP_UNBOUNDED:
+        //return INFINITE;
+      case CPXMIP_INFEASIBLE:
+        return INFEASIBLE;
+      default:
+        return UNDEFINED;
+    }
+    //Unboundedness not treated well: the following is from cplex 9.0 doc
+    // About Unboundedness
+
+    // The treatment of models that are unbounded involves a few
+    // subtleties. Specifically, a declaration of unboundedness means that
+    // ILOG CPLEX has determined that the model has an unbounded
+    // ray. Given any feasible solution x with objective z, a multiple of
+    // the unbounded ray can be added to x to give a feasible solution
+    // with objective z-1 (or z+1 for maximization models). Thus, if a
+    // feasible solution exists, then the optimal objective is
+    // unbounded. Note that ILOG CPLEX has not necessarily concluded that
+    // a feasible solution exists. Users can call the routine CPXsolninfo
+    // to determine whether ILOG CPLEX has also concluded that the model
+    // has a feasible solution.
+      
+  }  
+
+  MipCplex::Value MipCplex::_getPrimal(int i){
+    Value x;
+    CPXgetmipx(env, lp, &x, i, i);
+    return x;
+  }
+  
+  MipCplex::Value MipCplex::_getPrimalValue(){
+    Value objval;
+    status = CPXgetmipobjval(env, lp, &objval);
+    return objval;
+  }
+} //END OF NAMESPACE LEMON
+
+#endif //END OF MIP_CPLEX_CC

Added: hugo/trunk/lemon/mip_cplex.h
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/mip_cplex.h	Mon Sep 25 10:50:36 2006
@@ -0,0 +1,61 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_MIP_CPLEX_H
+#define LEMON_MIP_CPLEX_H
+
+///\file
+///\brief Header of the LEMON-CPLEX mip solver interface.
+///\ingroup gen_opt_group
+
+
+#include <lemon/lp_cplex.h>
+
+namespace lemon {
+
+  /// \brief Interface for the CPLEX MIP solver
+  /// 
+  /// This class implements an interface for the CPLEX MIP solver.
+  ///\ingroup gen_opt_group
+  class MipCplex : public MipSolverBase, public LpCplex{
+    
+  public:
+  
+    typedef MipSolverBase ParentMip;
+    typedef LpCplex ParentLp;
+    
+    MipCplex();
+    //~MipCplex();
+    
+    
+
+    
+  protected:
+  
+    virtual ColTypes _colType(int col);
+    virtual void _colType(int col, ColTypes col_type);
+    
+    virtual LpCplex::SolveExitStatus _solve();
+    virtual LpCplex::SolutionStatus _getMipStatus();
+    virtual ParentLp::Value _getPrimal(int i);
+    virtual ParentLp::Value _getPrimalValue();
+  };
+
+} //END OF NAMESPACE LEMON
+
+#endif // END OF LEMON_MIP_CPLEX_H

Added: hugo/trunk/lemon/mip_cplex.h~
==============================================================================
--- (empty file)
+++ hugo/trunk/lemon/mip_cplex.h~	Mon Sep 25 10:50:36 2006
@@ -0,0 +1,59 @@
+/* -*- C++ -*-
+ *
+ * This file is a part of LEMON, a generic C++ optimization library
+ *
+ * Copyright (C) 2003-2006
+ * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
+ * (Egervary Research Group on Combinatorial Optimization, EGRES).
+ *
+ * Permission to use, modify and distribute this software is granted
+ * provided that this copyright notice appears in all copies. For
+ * precise terms see the accompanying LICENSE file.
+ *
+ * This software is provided "AS IS" with no warranty of any kind,
+ * express or implied, and with no claim as to its suitability for any
+ * purpose.
+ *
+ */
+
+#ifndef LEMON_MIP_CPLEX_H
+#define LEMON_MIP_CPLEX_H
+
+///\file
+///\brief Header of the LEMON-CPLEX mip solver interface.
+///\ingroup gen_opt_group
+
+
+#include <lemon/lp_cplex.h>
+
+namespace lemon {
+  /// \brief Interface for the CPLEX MIP solver
+  /// 
+  /// This class implements an interface for the CPLEX MIP solver.
+  ///\ingroup gen_opt_group
+  class MipCplex : public MipSolverBase, public LpCplex{
+  
+  public:
+  
+    typedef MipSolverBase ParentMip;
+    typedef LpCplex ParentLp;
+    
+    MipCplex();
+    //~MipCplex();
+    
+    
+    
+  protected:
+  
+    virtual ColTypes _colType(int col);
+    virtual void _colType(int col, ColTypes col_type);
+    
+    virtual LpCplex::SolveExitStatus _solve();
+    virtual LpCplex::SolutionStatus _getMipStatus();
+    virtual ParentLp::Value _getPrimal(int i);
+    virtual ParentLp::Value _getPrimalValue();
+  };
+
+} //END OF NAMESPACE LEMON
+
+#endif // END OF LEMON_MIP_CPLEX_H



More information about the Lemon-commits mailing list