-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataOutput.cs
153 lines (123 loc) · 4.79 KB
/
DataOutput.cs
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections.Generic;
using System.Text;
using Google.OrTools.ConstraintSolver;
using System.Diagnostics;
using VrpTest.Struct;
namespace VrpTest
{
public class DataOutput : IDataOutput
{
public void PrintSolution(Day day,
RoutingModel routing,
RoutingIndexManager manager,
Assignment solution)
{
PrintToConsole(day, routing, manager, solution);
//ShowOnMap(day, routing, manager, solution);
}
public int PrintStatus(RoutingModel routing)
{
switch (routing.GetStatus())
{
case 0:
Console.WriteLine("Problem is not solved yet.");
return 0;
case 1:
Console.WriteLine("Problem is solved");
return 1;
case 2:
Console.WriteLine("No solution found to the problem.");
return 2;
case 3:
Console.WriteLine("Time limit reached before finding a solution.");
return 3;
case 4:
Console.WriteLine("Model, model parameters, or flags are not valid.");
return 4;
default:
return -1;
}
}
void ShowOnMap( Day day,
RoutingModel routing,
RoutingIndexManager manager,
Assignment solution)
{
List<List<int>> routes = new List<List<int>>();
for (int i = 0; i < day.Vehicles.Count; ++i)
{
var index = routing.Start(i);
List<int> route = new List<int>();
while (routing.IsEnd(index) == false)
{
route.Add(manager.IndexToNode((int)index));
index = solution.Value(routing.NextVar(index));
}
route.Add(manager.IndexToNode((int)index));
routes.Add(route);
}
for (int i = 0; i < routes.Count; i++)
{
string url = "https://www.google.com.tr/maps/dir/";
foreach (var item in routes[i])
{
url += day.Addresses[item].Replace('+',',') + "/";
}
//url += data.addresses[data.Depot];
Process process = new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = "chrome";
process.StartInfo.Arguments = url;
process.Start();
}
}
public void PrintToConsole(
Day day,
RoutingModel routing,
RoutingIndexManager manager,
Assignment solution)
{
Console.WriteLine("Day " + day.DayNum);
if (day.Locations.Count != 0)
{
// Display dropped nodes.
string droppedNodes = "Dropped nodes:";
for (int index = 0; index < routing.Size(); ++index)
{
if (routing.IsStart(index) || routing.IsEnd(index))
{
continue;
}
if (solution.Value(routing.NextVar(index)) == index)
{
droppedNodes += " " + manager.IndexToNode(index);
}
}
Console.WriteLine("{0}", droppedNodes);
// Inspect solution.
for (int i = 0; i < day.Vehicles.Count; i++)
{
Console.WriteLine("Route for Vehicle {0}:", i);
long routeDuration = 0;
var index = routing.Start(i);
while (routing.IsEnd(index) == false)
{
Console.Write("{0} -> ", manager.IndexToNode((int)index));
var previousIndex = index;
index = solution.Value(routing.NextVar(index));
routeDuration += routing.GetArcCostForVehicle(previousIndex, index, 0);
}
Console.WriteLine("{0}", manager.IndexToNode((int)index));
Console.WriteLine("Duration of the route: {0}mins", routeDuration);
}
Console.WriteLine("Minimum duration of the routes: {0}mins", day.MinDur);
Console.WriteLine("Maximum duration of the routes: {0}mins", day.MaxDur);
}
else
{
Console.WriteLine("This day is holiday.");
}
}
}
}