/home/coin/SVN-release/CoinAll-1.1.0/Blis/examples/VRP/VrpSolution.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 VrpSolution_h_
00016 #define VrpSolution_h_
00017 
00018 #include "BlisSolution.h"
00019 
00020 #include "VrpModel.h"
00021 
00022 //#############################################################################
00024 //#############################################################################
00025 
00026 class VrpSolution : public BlisSolution {
00027 
00028 protected:
00029 
00030    _node *opt_;
00031     
00032 public:
00033     
00035    VrpSolution() : BlisSolution(), opt_(0)
00036         {}
00037 
00039    VrpSolution(int s, const double *values, double objValue, VrpModel *vrp=0);
00040    
00042    virtual ~VrpSolution(){
00043       delete [] opt_;
00044    }
00045 
00047    void setOpt(_node *opt) { 
00048        if (opt_) delete opt_;
00049        opt_ = opt; 
00050    }
00051    
00053    virtual void print(std::ostream& os) const; 
00054    
00056    virtual AlpsEncoded* encode() const {
00057       AlpsEncoded* encoded = new AlpsEncoded(AlpsKnowledgeTypeSolution);
00058       encodeBcps(encoded);
00059 
00060       //Vrp part.
00061       int cur_vert = opt_[0].next, count = 1;  
00062       while (cur_vert != 0){
00063           cur_vert = opt_[cur_vert].next;
00064           ++count;
00065       }
00066       encoded->writeRep(count);
00067       for (int j = 0; j < count; ++j) {
00068           encoded->writeRep(opt_[j].next);
00069           encoded->writeRep(opt_[j].route);
00070       }
00071 
00072       return encoded;
00073    }
00074    
00076    virtual AlpsKnowledge* decode(AlpsEncoded& encoded) const {
00077       VrpSolution * sol = new VrpSolution();
00078       sol->decodeBcps(encoded);
00079 
00080       // Vrp part.
00081       int count;
00082       encoded.readRep(count);
00083       _node *opt = new _node [count];
00084       for (int j = 0; j < count; ++j) {
00085           encoded.readRep(opt[j].next);
00086           encoded.readRep(opt[j].route);
00087       }
00088       sol->setOpt(opt);
00089       
00090       return sol;
00091    }
00092    
00093 };
00094 
00095 //#############################################################################
00096 //#############################################################################
00097 
00098 #endif

Generated on Sun Nov 14 14:06:30 2010 for Coin-All by  doxygen 1.4.7