VrpSolution.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of a solver for the Vehicle Routing Problem *
3  * developed using the BiCePS Linear Integer Solver (BLIS). *
4  * *
5  * This solver is distributed under the Eclipse Public License as part of *
6  * the COIN-OR repository (http://www.coin-or.org). *
7  * *
8  * Authors: Yan Xu, Lehigh University *
9  * Ted Ralphs, Lehigh University *
10  * *
11  * Copyright (C) 2007 Yan Xu and Ted Ralphs. *
12  * All Rights Reserved. *
13  *===========================================================================*/
14 
15 #ifndef VrpSolution_h_
16 #define VrpSolution_h_
17 
18 #include "BlisSolution.h"
19 
20 #include "VrpModel.h"
21 
22 //#############################################################################
24 //#############################################################################
25 
26 class VrpSolution : public BlisSolution {
27 
28 protected:
29 
31 
32 public:
33 
36  {}
37 
39  VrpSolution(int s, const double *values, double objValue, VrpModel *vrp=0);
40 
42  virtual ~VrpSolution(){
43  delete [] opt_;
44  }
45 
47  void setOpt(_node *opt) {
48  if (opt_) delete opt_;
49  opt_ = opt;
50  }
51 
53  virtual void print(std::ostream& os) const;
54 
56  virtual AlpsEncoded* encode() const {
58  encodeBcps(encoded);
59 
60  //Vrp part.
61  int cur_vert = opt_[0].next, count = 1;
62  while (cur_vert != 0){
63  cur_vert = opt_[cur_vert].next;
64  ++count;
65  }
66  encoded->writeRep(count);
67  for (int j = 0; j < count; ++j) {
68  encoded->writeRep(opt_[j].next);
69  encoded->writeRep(opt_[j].route);
70  }
71 
72  return encoded;
73  }
74 
76  virtual AlpsKnowledge* decode(AlpsEncoded& encoded) const {
77  VrpSolution * sol = new VrpSolution();
78  sol->decodeBcps(encoded);
79 
80  // Vrp part.
81  int count;
82  encoded.readRep(count);
83  _node *opt = new _node [count];
84  for (int j = 0; j < count; ++j) {
85  encoded.readRep(opt[j].next);
86  encoded.readRep(opt[j].route);
87  }
88  sol->setOpt(opt);
89 
90  return sol;
91  }
92 
93 };
94 
95 //#############################################################################
96 //#############################################################################
97 
98 #endif
AlpsEncoded & readRep(T &value)
Read a single object of type T from repsentation_ .
Definition: AlpsEncoded.h:173
void setOpt(_node *opt)
Set opt.
Definition: VrpSolution.h:47
AlpsEncoded & writeRep(const T &value)
Write a single object of type T in repsentation_ .
Definition: AlpsEncoded.h:163
Model class for VRP.
Definition: VrpModel.h:32
virtual AlpsKnowledge * decode(AlpsEncoded &encoded) const
The method that decodes the solution from a encoded object.
Definition: VrpSolution.h:76
virtual ~VrpSolution()
Destructor.
Definition: VrpSolution.h:42
int next
AlpsReturnStatus decodeBcps(AlpsEncoded &encoded)
Unpack Bcps part of solution from an encoded objects.
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
virtual AlpsEncoded * encode() const
The method that encodes the solution into a encoded object.
Definition: VrpSolution.h:56
virtual void print(std::ostream &os) const
Print the solution.
AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const
Pack Bcps part of solution into an encoded objects.
This class contains the solutions generated by the LP solver (either primal or dual.
Definition: BlisSolution.h:36
VrpSolution()
Default constructor.
Definition: VrpSolution.h:35
The abstract base class of any user-defined class that Alps has to know about in order to encode/deco...
Definition: AlpsKnowledge.h:51
This class contains a vrp solution.
Definition: VrpSolution.h:26
_node * opt_
Definition: VrpSolution.h:30