- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# /home/coin/SVN-release/Blis-0.91.0/Blis/examples/VRP/VrpVariable.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of a solver for the Vehicle Routing Problem             *
    00003  * developed using the BiCePS Linear Integer Solver (BLIS).                  *
    00004  *                                                                           *
    00005  * This solver is distributed under the Common Public License as part of     *
    00006  * the COIN-OR repository (http://www.coin-or.org).                          *
    00007  *                                                                           *
    00008  * Authors: Yan Xu, Lehigh University                                        *
    00009  *          Ted Ralphs, Lehigh University                                    *
    00010  *                                                                           *
    00011  * Copyright (C) 2007 Yan Xu and Ted Ralphs.                                 *
    00012  * All Rights Reserved.                                                      *
    00013  *===========================================================================*/
    00014
    00015 #ifndef VrpVariable_h_
    00016 #define VrpVariable_h_
    00017
    00018 //#############################################################################
    00019
    00020 #include "BlisVariable.h"
    00021
    00022 //#############################################################################
    00023
    00025 class VrpVariable : public BlisVariable
    00026 {
    00027 private:
    00028
    00029     /* The endpoints of the edge */
    00030     int ends_[2];
    00031     int uind_;
    00032
    00033 protected:
    00034
    00036     AlpsReturnStatus encodeVrp(AlpsEncoded *encoded) {
    00037         AlpsReturnStatus status = AlpsReturnStatusOk;
    00038
    00039         //std::cout << "****** encodeVrp var: size_ = " << size_ << std::endl;
    00040
    00041         encoded->writeRep(ends_[0]);
    00042         encoded->writeRep(ends_[1]);
    00043         encoded->writeRep(uind_);
    00044
    00045         return status;
    00046     }
    00047
    00049     AlpsReturnStatus decodeVrp(AlpsEncoded &encoded) {
    00050         AlpsReturnStatus status = AlpsReturnStatusOk;
    00051
    00052         encoded.readRep(ends_[0]);
    00053         encoded.readRep(ends_[1]);
    00054         encoded.readRep(uind_);
    00055
    00056         //std::cout << "****** decodeVrp var: size_ = " << size_ << std::endl;
    00057
    00058         return status;
    00059     }
    00060
    00061 public:
    00062
    00064     VrpVariable() {
    00065        ends_[0] = 0;
    00066        ends_[1] = 0;
    00067     }
    00068
    00070     VrpVariable(int v1, int v2, int cost, int ub) {
    00071        ends_[0] = v1 < v2 ? v1 : v2;
    00072        ends_[1] = v1 < v2 ? v2 : v1;
    00073        uind_ = ends_[1]*(ends_[1] - 1)/2 + ends_[0];
    00074        int indices [2];
    00075        double values [2];
    00076        indices[0] = ends_[0];
    00077        indices[1] = ends_[1];
    00078        values[0] = values[1] = 1.0;
    00079        setData(2, indices, values);
    00080        setIntType('B');
    00081        setLbHard(0.0);
    00082        setUbHard((double) ub);
    00083        setObjCoef((double) cost);
    00084     }
    00085
    00087     virtual ~VrpVariable() {
    00088         //std::cout << "delete a vrp variable " << std::endl;
    00089     }
    00090
    00093     inline int getIndex() { return uind_; }
    00094     inline int getv0() { return ends_[0]; }
    00095     inline int getv1() { return ends_[1]; }
    00099     virtual AlpsReturnStatus encode(AlpsEncoded *encoded){
    00100         AlpsReturnStatus status;
    00101
    00102         status = encodeBcpsObject(encoded);
    00103         status = encodeBlis(encoded);
    00104         status = encodeVrp(encoded);
    00105
    00106         return status;
    00107     }
    00108
    00110     virtual AlpsKnowledge* decode(AlpsEncoded &encoded) const {
    00111         AlpsReturnStatus status = AlpsReturnStatusOk;
    00112         VrpVariable * var = new VrpVariable();
    00113
    00114         // Unpack Bcps part.
    00115         status = var->decodeBcpsObject(encoded);
    00116         if (status) {
    00117             throw CoinError("Failed to decode Bcps part of var",
    00118                             "decode",
    00119                             "BlisObject");
    00120         }
    00121
    00122         // Unpack Blis part.
    00123         status = var->decodeBlis(encoded);
    00124         if (status) {
    00125             throw CoinError("Failed to decode Blis part of var",
    00126                             "decode",
    00127                             "BlisObject");
    00128         }
    00129
    00130         // Unpack Vrp part.
    00131         status = var->decodeVrp(encoded);
    00132         if (status) {
    00133             throw CoinError("Failed to decode Vrp part of var",
    00134                             "decode",
    00135                             "BlisObject");
    00136         }
    00137         return var;
    00138     }
    00139
    00140 };
    00141
    00142 //#############################################################################
    00143
    00144 #endif