@@ -20,8 +20,7 @@ public class UsingCoSkyAPIv2 {
2020 public static void main (String [] args ) {
2121 API api = new API ("" );
2222 boolean success = api .authenticate ("" , "" );
23-
24-
23+
2524 if (success ) {
2625 try {
2726 ApiData data = api .navigate (ApiData .class , api .getRoot ());
@@ -31,57 +30,56 @@ public static void main (String[] args) {
3130 System .out .println (datas );
3231 UserData user = api .navigate (UserData .class , datas .getLocation ());
3332
34- EntityLinkCollection users = api .navigate (EntityLinkCollection .class , data .getLink ("list-users" ));
33+ UserDataSet users = api .navigate (UserDataSet .class , data .getLink ("list-users" ));
3534
36- for (EntityLink u : users .getItems ()) {
35+ for (UserData u : users .getItems ()) {
3736 System .out .println (u );
3837 }
3938
40-
4139 if (user != null ) {
4240
43- EntityLinkCollection problems = api .navigate (EntityLinkCollection .class , user .getLink ("list-problems" ));
41+ RoutingProblemDataSet problems = api .navigate (RoutingProblemDataSet .class , user .getLink ("list-problems" ));
4442
4543 RoutingProblemUpdateRequest newProblem = new RoutingProblemUpdateRequest ("exampleProblem" );
4644 ResponseData result = api .navigate (ResponseData .class , user .getLink ("create-problem" ), newProblem );
4745 System .out .println (result );
48- problems = api .navigate (EntityLinkCollection .class , user .getLink ("list-problems" ));
46+ problems = api .navigate (RoutingProblemDataSet .class , user .getLink ("list-problems" ));
4947 RoutingProblemData problem1 = api .navigate (RoutingProblemData .class , problems .getItems ().get (0 ).getLink ("self" ));
5048
5149 System .out .println (problem1 );
5250 CoordinateData coordinateData = new CoordinateData ();
53-
54- // coordinateData.setLatitude(62.244588);
55- // coordinateData.setLongitude(25.742683);
51+
52+ coordinateData .setLatitude (62.244588 );
53+ coordinateData .setLongitude (25.742683 );
5654
5755 //Saksa
58- coordinateData .setLatitude (54.130888 );
59- coordinateData .setLongitude (12.00938 );
56+ // coordinateData.setLatitude(54.130888);
57+ // coordinateData.setLongitude(12.00938);
6058 coordinateData .setSystem (CoordinateData .CoordinateSystem .WGS84 );
6159 LocationData locationData = new LocationData ();
6260 locationData .setCoordinatesData (coordinateData );
6361
6462 CoordinateData pickup = new CoordinateData ();
6563
6664
67- // pickup.setLatitude(62.247906);
68- // pickup.setLongitude(25.867395);
65+ pickup .setLatitude (62.247906 );
66+ pickup .setLongitude (25.867395 );
6967
7068 //Saksa
71- pickup .setLatitude (54.14454 );
72- pickup .setLongitude (12.108808 );
69+ // pickup.setLatitude(54.14454);
70+ // pickup.setLongitude(12.108808);
7371 pickup .setSystem (CoordinateData .CoordinateSystem .WGS84 );
7472 LocationData pickupLocation = new LocationData ();
7573 pickupLocation .setCoordinatesData (pickup );
7674
7775 CoordinateData delivery = new CoordinateData ();
7876
79- // delivery.setLatitude(61.386909);
80- // delivery.setLongitude(24.654106);
77+ delivery .setLatitude (61.386909 );
78+ delivery .setLongitude (24.654106 );
8179
8280 //Saksa
83- delivery .setLatitude (53.545867 );
84- delivery .setLongitude (10.276409 );
81+ // delivery.setLatitude(53.545867);
82+ // delivery.setLongitude(10.276409);
8583 delivery .setSystem (CoordinateData .CoordinateSystem .WGS84 );
8684 LocationData deliveryLocation = new LocationData ();
8785 deliveryLocation .setCoordinatesData (delivery );
@@ -96,47 +94,44 @@ public static void main (String[] args) {
9694 timeWindows .add (new TimeWindowData (morning , evening ));
9795
9896 VehicleUpdateRequest vehicleRequest = new VehicleUpdateRequest ("demoVehicle" ,capacities , locationData , locationData );
97+ VehicleUpdateRequest vehicle2 = new VehicleUpdateRequest ("demoVehicle2" ,capacities , locationData , locationData );
9998 vehicleRequest .setTimeWindows (timeWindows );
100-
101- result = api .navigate (ResponseData .class , problem1 .getLink ("create-vehicle" ), vehicleRequest );
102-
103- EntityLinkCollection vehicles = api .navigate (EntityLinkCollection .class , problem1 .getLink ("list-vehicles" ));
104-
105- for ( EntityLink zdf : vehicles .getItems ()) {
106- System .out .println (zdf );
107- }
108-
99+ vehicle2 .setTimeWindows (timeWindows );
100+
101+ //New way to add many vehicles at the same time, is WAY faster than doing it one by one.
102+ VehicleSetImportRequest vehicles = new VehicleSetImportRequest ();
103+ ArrayList <VehicleUpdateRequest > set = new ArrayList <VehicleUpdateRequest >();
104+ set .add (vehicle2 );
105+ set .add (vehicleRequest );
106+ vehicles .setItems (set );
107+ result = api .navigate (ResponseData .class , problem1 .getLink ("import-vehicles" ), vehicles );
108+
109+
109110 ArrayList <CapacityData > taskCapacity = new ArrayList <CapacityData >();
110111 taskCapacity .add (new CapacityData ("Weight" , 1 ));
111-
112+ ArrayList < TaskUpdateRequest > tasks = new ArrayList < TaskUpdateRequest >();
112113 for (int i = 0 ; i < 4 ; i ++) {
113- ArrayList <TaskEventUpdateRequest > taskEvents = new ArrayList <TaskEventUpdateRequest >();
114+ ArrayList <TaskEventUpdateRequest > taskEvents = new ArrayList <TaskEventUpdateRequest >();
114115 taskEvents .add (new TaskEventUpdateRequest (Type .Pickup , pickupLocation , taskCapacity ));
115116 taskEvents .add (new TaskEventUpdateRequest (Type .Delivery , deliveryLocation , taskCapacity ));
116117 TaskUpdateRequest task = new TaskUpdateRequest (taskEvents );
117- task .setName ("testTask" );
118+ task .setName ("testTask" + i );
118119 taskEvents .get (0 ).setTimeWindows (timeWindows );
119120 taskEvents .get (1 ).setTimeWindows (timeWindows );
120121 taskEvents .get (0 ).setServiceTime (10 );
121122 taskEvents .get (1 ).setServiceTime (10 );
122-
123- result = api .navigate (ResponseData .class , problem1 .getLink ("create-task" ), task );
124-
123+ tasks .add (task );
125124 }
126-
125+
126+ //New way to add many tasks in one request, is WAY faster than doing it one by one.
127+ TaskSetImportRequest taskeSetImport = new TaskSetImportRequest ();
128+ taskeSetImport .setItems (tasks );
129+ result = api .navigate (ResponseData .class , problem1 .getLink ("import-tasks" ), taskeSetImport );
130+
127131 ArrayList <TaskEventData > taskEvents = new ArrayList <TaskEventData >();
128132 taskEvents .add (new TaskEventData (Type .Pickup , pickupLocation , taskCapacity ));
129133 taskEvents .add (new TaskEventData (Type .Delivery , deliveryLocation , taskCapacity ));
130-
131- if (result .getItems () != null ) {
132- System .out .println (result .getItems ());
133- }
134-
135- TaskDataSet taskData = api .navigate (TaskDataSet .class , problem1 .getLink ("list-tasks" ) );
136- for (TaskData td : taskData .getItems ()) {
137- System .out .println (td );
138- }
139-
134+
140135 problem1 = api .navigate (RoutingProblemData .class , problem1 .getLink ("self" ));
141136 System .out .println (problem1 );
142137 //starting optimization
@@ -154,35 +149,30 @@ public static void main (String[] args) {
154149 Thread .sleep (1500 );
155150 problem1 = api .navigate (RoutingProblemData .class , problem1 .getLink ("self" ));
156151 System .out .println ("Optimization is " + problem1 .getState () +" at percentage " + problem1 .getProgress ());
152+ /*
157153 objectiveValues = api.navigate(ObjectiveValueDataSet.class, problem1.getLink("objective-values"), qp);
158154
159155 if (objectiveValues != null && !objectiveValues.getItems().isEmpty()) {
160156 for (ObjectiveValueData item : objectiveValues.getItems()) {
161157 System.out.println( "Objective values from " + qp.get("start") + " to " + qp.get("end") + ": [" + item.getTimeStamp() + "] " + item.getValue() );
162158 }
163159 }
164-
160+ */
165161 if (problem1 .getState ().equals ("Stopped" )) break ;
166162 } catch (InterruptedException e ) {
167163 e .printStackTrace ();
168164 }
169165 }
170166
171- EntityLinkCollection v = api .navigate (EntityLinkCollection .class , problem1 .getLink ("list-vehicles " ));
167+ PlanData v = api .navigate (PlanData .class , problem1 .getLink ("plan " ));
172168
173- //Gets the routeevent
174- for (EntityLink el : v .getItems ()) {
175- VehicleData vd = api .navigate (VehicleData .class , el .getLink ("self" ));
176- System .out .println ("Vehicles route: " );
177- RouteEventDataSet routeEvents = api .navigate (RouteEventDataSet .class , vd .getLink ("list-events" ));
178- for (RouteEventData red : routeEvents .getItems ()) {
179- System .out .println (red );
180- }
169+ //Go through the plan.
170+ for (FieldsItem el : v .getItems ()) {
171+ System .out .println (el );
181172 }
182- //Tasks do not contain the information about their task events anymore.
183173 }
184-
185- } catch (NFleetException e ) {
174+
175+ } catch (NFleetRequestException e ) {
186176 System .out .println ("Something went wrong" );
187177 } catch (IOException e ) {
188178 System .out .println (e );
0 commit comments