-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolver.h
55 lines (49 loc) · 2.23 KB
/
solver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef SOLVER_H
#define SOLVER_H
#include "instance_util.h"
#define OUTPUT_DIRECTORY "./solutions/"
typedef std::pair<char, int> nodeKey;
typedef std::pair<std::pair<int, double>, std::pair<double, double>> AFSDepotRouteInfo;
typedef std::pair<nodeKey, nodeKey> swapPair;
double distanceHarvesine(double lon1, double lat1, double lon2, double lat2);
void printNodeKeyVector(std::vector<nodeKey> v);
void printMovement(swapPair p);
class vehicleSolution {
public:
double vehicleAcumTime; // total travel time acumulated by the vehicle
double vehicleSolQuality; // total distance traveled by the vehicle
int vehicleClients; // number of clients visited by the vehicle
std::vector<nodeKey> route; // the route taken by the vehicle
double exceededDist; // exceeded distance (if any)
void setVehicleSolution(std::vector<nodeKey> r, double time, double quality, int clients);
vehicleSolution();
~vehicleSolution();
};
class GVRPSolver {
private:
Instance* curInstance; // current instance
std::string solDir; // solution directory
double solQuality; // total distance for all vehicles
int numVehicle; // final vehicle quantity
int numVisitedClients; // total of clientes serviced for all vehicles
double executionTime; // total execution time
std::vector<int> visitedCustomerNodes; // array with visited clients (1=visited, 0=othervise)
std::vector<vehicleSolution> vehicleRoutes; // vector with solutions for each vehicle
public:
vehicleSolution greedySearch();
vehicleSolution tabuSearch(vehicleSolution greedySol);
swapPair makeMovementPair(nodeKey node1, nodeKey node2);
Node findNodeByType(nodeKey n);
AFSDepotRouteInfo findRouteToDepot(double acumDist, double acumTime, double lon1, double lat1);
std::string routeToString(std::vector<nodeKey> r);
int isTabu(std::vector<swapPair> tabu, swapPair movement);
double calculateExceededDistance(vehicleSolution s);
bool isValidSolution(vehicleSolution s);
void setExecTime(double seconds);
void writeSolution();
void recalculateTimeQuality(vehicleSolution* s, int i, int j);
void generateNewSol(vehicleSolution* s, int i, int j);
GVRPSolver(Instance* instance);
~GVRPSolver();
};
#endif