Operational Research Library  1.0
CapacitatedVehicleRoutingProblem.h
Go to the documentation of this file.
1 #ifndef CAPACITATEDVEHICLEROUTINGPROBLEM_H
2 #define CAPACITATEDVEHICLEROUTINGPROBLEM_H
3 
4 #include <iostream>
5 #include <fstream>
6 #include <sstream>
7 #include <algorithm>
8 #include <vector>
9 #include "RandomHelper.h"
10 #include "CoordinatesHelper.h"
11 #include "IData.h"
12 
13 namespace operational_research
14 {
15 
24 {
25 private:
26  // Number of objects.
27  unsigned int customers;
28 
29  // Demands of customers.
30  std::vector<double> demands;
31 
32  // Coordinates of depot and customers.
33  std::vector<CoordinatesHelper> coordinates;
34 
35  // Vehicle capacity.
36  double capacity;
37 
43  bool checkSchedule(const std::vector<unsigned int>& schedule);
44 
52  void writeResultToFile(const std::vector<unsigned int>& schedule, double costFunctionValue, const std::string& filename);
53 
54 public:
63  CapacitatedVehicleRoutingProblem(unsigned int customers, const std::vector<double>& demands, const std::vector<CoordinatesHelper>& coordinates, double capacity);
64 
76  CapacitatedVehicleRoutingProblem(unsigned int customers, double capacity, double minDemand, double maxDemand, double minCoordinate, double maxCoordinate, bool integerValues = false);
77 
84  CapacitatedVehicleRoutingProblem(const std::string& filename);
85 
94  void setData(unsigned int customers, const std::vector<double>& demands, const std::vector<CoordinatesHelper>& coordinates, double capacity);
95 
107  void generateData(unsigned int customers, double capacity, double minDemand, double maxDemand, double minCoordinate, double maxCoordinate, bool integerValues = false);
108 
115  void readDataFromFile(const std::string& filename);
116 
122  void writeDataToFile(const std::string& filename);
123 
127  void showData();
128 
135  double evaluateCVRP(const std::vector<unsigned int>& schedule);
136 
145  double evaluateCVRP(const std::vector<unsigned int>& schedule, const std::string& filename);
146 
151  double getCapacity() const {
152  return capacity;
153  }
154 
159  const std::vector<CoordinatesHelper>& getCoordinates() const {
160  return coordinates;
161  }
162 
167  unsigned int getCustomers() const {
168  return customers;
169  }
170 
175  const std::vector<double>& getDemands() const {
176  return demands;
177  }
178 };
179 
180 } // namespace operational_research
181 
182 #endif // CAPACITATEDVEHICLEROUTINGPROBLEM_H
CapacitatedVehicleRoutingProblem(unsigned int customers, const std::vector< double > &demands, const std::vector< CoordinatesHelper > &coordinates, double capacity)
Constructor.
Definition: CapacitatedVehicleRoutingProblem.cpp:11
Simple coordinates class.
Interface for reading, writing and displaying data.
Definition: BinPackingProblem.cpp:3
void writeDataToFile(const std::string &filename)
Writes capacitated vehicle routing problem data to a file with a filename.
Definition: CapacitatedVehicleRoutingProblem.cpp:300
void generateData(unsigned int customers, double capacity, double minDemand, double maxDemand, double minCoordinate, double maxCoordinate, bool integerValues=false)
Generates capacitated vehicle routing problem data according to setup.
Definition: CapacitatedVehicleRoutingProblem.cpp:79
double getCapacity() const
Getter for vehicle capacity.
Definition: CapacitatedVehicleRoutingProblem.h:151
Definition: CapacitatedVehicleRoutingProblem.h:23
void readDataFromFile(const std::string &filename)
Reads capacitated vehicle routing problem data from a file with a filename.
Definition: CapacitatedVehicleRoutingProblem.cpp:145
Simple pseudo random number generator class.
const std::vector< double > & getDemands() const
Getter for demands of customers.
Definition: CapacitatedVehicleRoutingProblem.h:175
double evaluateCVRP(const std::vector< unsigned int > &schedule)
Evaluates capacitated vehicle routing problem.
Definition: CapacitatedVehicleRoutingProblem.cpp:41
void setData(unsigned int customers, const std::vector< double > &demands, const std::vector< CoordinatesHelper > &coordinates, double capacity)
Setter for capacitated vehicle routing problem data.
Definition: CapacitatedVehicleRoutingProblem.cpp:252
void showData()
Shows capacitated vehicle routing problem data.
Definition: CapacitatedVehicleRoutingProblem.cpp:287
unsigned int getCustomers() const
Getter for number of customers.
Definition: CapacitatedVehicleRoutingProblem.h:167
Definition: IData.h:14
const std::vector< CoordinatesHelper > & getCoordinates() const
Getter for coordinates of customers.
Definition: CapacitatedVehicleRoutingProblem.h:159