Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUsingCoSkyAPIv2.java
More file actions
Latest commit
187 lines (150 loc) · 9.6 KB
/
Copy pathUsingCoSkyAPIv2.java
File metadata and controls
187 lines (150 loc) · 9.6 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
importjava.io.IOException;
importjava.util.ArrayList;
importjava.util.Date;
importjava.util.HashMap;
importfi.cosky.sdk.*;
/*
* This file is subject to the terms and conditions defined in
* file 'LICENSE.txt', which is part of this source code package.
*/
/**
* Example program to demonstrate how to use the CO-SKY RESTful API
* For reporting bugs in the SDK, please contact dev-support (at) co-sky.fi
*/
publicclassUsingCoSkyAPIv2 {
@SuppressWarnings("deprecation")
publicstaticvoidmain (String[] args) {
APIapi = newAPI("");
booleansuccess = api.authenticate("", "");
if (success) {
try {
ApiDatadata = api.navigate(ApiData.class, api.getRoot());
System.out.println(data);
ResponseDatadatas = api.navigate(ResponseData.class, data.getLink("create-user"), newUserData());
System.out.println(datas);
UserDatauser = api.navigate(UserData.class, datas.getLocation());
UserDataSetusers = api.navigate(UserDataSet.class, data.getLink("list-users"));
for (UserDatau : users.getItems()) {
System.out.println(u);
}
if (user != null) {
RoutingProblemDataSetproblems = api.navigate(RoutingProblemDataSet.class, user.getLink("list-problems"));
RoutingProblemUpdateRequestnewProblem = newRoutingProblemUpdateRequest("exampleProblem");
ResponseDataresult = api.navigate(ResponseData.class, user.getLink("create-problem"), newProblem );
System.out.println(result);
problems = api.navigate(RoutingProblemDataSet.class, user.getLink("list-problems"));
RoutingProblemDataproblem1 = api.navigate(RoutingProblemData.class, problems.getItems().get(0).getLink("self"));
System.out.println(problem1);
CoordinateDatacoordinateData = newCoordinateData();
coordinateData.setLatitude(62.244588);
coordinateData.setLongitude(25.742683);
//Saksa
//coordinateData.setLatitude(54.130888);
//coordinateData.setLongitude(12.00938);
coordinateData.setSystem(CoordinateData.CoordinateSystem.WGS84);
LocationDatalocationData = newLocationData();
locationData.setCoordinatesData(coordinateData);
CoordinateDatapickup = newCoordinateData();
pickup.setLatitude(62.247906);
pickup.setLongitude(25.867395);
//Saksa
//pickup.setLatitude(54.14454);
//pickup.setLongitude(12.108808);
pickup.setSystem(CoordinateData.CoordinateSystem.WGS84);
LocationDatapickupLocation = newLocationData();
pickupLocation.setCoordinatesData(pickup);
CoordinateDatadelivery = newCoordinateData();
delivery.setLatitude(61.386909);
delivery.setLongitude(24.654106);
//Saksa
//delivery.setLatitude(53.545867);
//delivery.setLongitude(10.276409);
delivery.setSystem(CoordinateData.CoordinateSystem.WGS84);
LocationDatadeliveryLocation = newLocationData();
deliveryLocation.setCoordinatesData(delivery);
ArrayList<CapacityData> capacities = newArrayList<CapacityData>();
capacities.add(newCapacityData("Weight", 100000));
ArrayList<TimeWindowData> timeWindows = newArrayList<TimeWindowData>();
Datemorning = newDate();
morning.setHours(7);
Dateevening = newDate();
evening.setHours(16);
timeWindows.add(newTimeWindowData(morning, evening));
VehicleUpdateRequestvehicleRequest = newVehicleUpdateRequest("demoVehicle",capacities, locationData, locationData);
VehicleUpdateRequestvehicle2 = newVehicleUpdateRequest("demoVehicle2",capacities, locationData, locationData);
vehicleRequest.setTimeWindows(timeWindows);
vehicle2.setTimeWindows(timeWindows);
//New way to add many vehicles at the same time, is WAY faster than doing it one by one.
VehicleSetImportRequestvehicles = newVehicleSetImportRequest();
ArrayList<VehicleUpdateRequest> set = newArrayList<VehicleUpdateRequest>();
set.add(vehicle2);
set.add(vehicleRequest);
vehicles.setItems(set);
result = api.navigate(ResponseData.class, problem1.getLink("import-vehicles"), vehicles);
ArrayList<CapacityData> taskCapacity = newArrayList<CapacityData>();
taskCapacity.add(newCapacityData("Weight", 1));
ArrayList<TaskUpdateRequest> tasks = newArrayList<TaskUpdateRequest>();
for (inti = 0 ; i < 4; i++) {
ArrayList<TaskEventUpdateRequest> taskEvents = newArrayList<TaskEventUpdateRequest>();
taskEvents.add(newTaskEventUpdateRequest(Type.Pickup, pickupLocation, taskCapacity));
taskEvents.add(newTaskEventUpdateRequest(Type.Delivery, deliveryLocation, taskCapacity));
TaskUpdateRequesttask = newTaskUpdateRequest(taskEvents);
task.setName("testTask" + i);
taskEvents.get(0).setTimeWindows(timeWindows);
taskEvents.get(1).setTimeWindows(timeWindows);
taskEvents.get(0).setServiceTime(10);
taskEvents.get(1).setServiceTime(10);
tasks.add(task);
}
//New way to add many tasks in one request, is WAY faster than doing it one by one.
TaskSetImportRequesttaskeSetImport = newTaskSetImportRequest();
taskeSetImport.setItems(tasks);
result = api.navigate(ResponseData.class, problem1.getLink("import-tasks"), taskeSetImport);
ArrayList<TaskEventData> taskEvents = newArrayList<TaskEventData>();
taskEvents.add(newTaskEventData(Type.Pickup, pickupLocation, taskCapacity));
taskEvents.add(newTaskEventData(Type.Delivery, deliveryLocation, taskCapacity));
problem1 = api.navigate(RoutingProblemData.class, problem1.getLink("self"));
System.out.println(problem1);
//starting optimization
problem1.setState("Running");
result = api.navigate(ResponseData.class, problem1.getLink("toggle-optimization"), problem1.toRequest());
System.out.println(result);
//stopping optimization would be the same but set state to "Stopped"
ObjectiveValueDataSetobjectiveValues = null;
HashMap<String, String> qp = newHashMap<String, String>();
qp.put("start", "0");
qp.put("end", "10");
while (true) {
try {
Thread.sleep(1500);
problem1 = api.navigate(RoutingProblemData.class, problem1.getLink("self"));
System.out.println("Optimization is " + problem1.getState() +" at percentage " + problem1.getProgress());
/*
objectiveValues = api.navigate(ObjectiveValueDataSet.class, problem1.getLink("objective-values"), qp);
if (objectiveValues != null && !objectiveValues.getItems().isEmpty()) {
for (ObjectiveValueData item : objectiveValues.getItems()) {
System.out.println( "Objective values from " + qp.get("start") + " to " + qp.get("end") + ": [" + item.getTimeStamp() + "] " + item.getValue() );
}
}
*/
if (problem1.getState().equals("Stopped")) break;
} catch (InterruptedExceptione) {
e.printStackTrace();
}
}
PlanDatav = api.navigate(PlanData.class, problem1.getLink("plan"));
//Go through the plan.
for (VehiclePlanDatael : v.getItems()) {
System.out.println(el);
}
}
} catch (NFleetRequestExceptione) {
System.out.println("Something went wrong");
} catch (IOExceptione) {
System.out.println(e);
}
} else {
System.out.println("Credentials were wrong, or the service is unavailable");
}
}
}