{"_id":"5739b6a9d5b6db0e00729d58","category":{"_id":"5706099c21cfed0e00e8c60f","project":"5706099c21cfed0e00e8c60b","version":"5706099c21cfed0e00e8c60e","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-04-07T07:17:48.833Z","from_sync":false,"order":0,"slug":"documentation","title":"Introduction"},"__v":24,"githubsync":"","project":"5706099c21cfed0e00e8c60b","version":{"_id":"5706099c21cfed0e00e8c60e","hasDoc":true,"project":"5706099c21cfed0e00e8c60b","__v":6,"hasReference":true,"createdAt":"2016-04-07T07:17:48.808Z","releaseDate":"2016-04-07T07:17:48.808Z","categories":["5706099c21cfed0e00e8c60f","573548f4afab4417007239cf","57354970fc5f1e0e001a463c","573549791f16241700c89fc9","57441052583f470e000a7947","57a068f90c933e0e00249bae"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.17","version":"1.0.17"},"parentDoc":null,"user":"570614bde2df830e00d52774","metadata":{"title":"","description":"","image":[]},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-05-16T12:01:45.468Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":4,"body":"# The Workflow\nAs mentioned earlier, at the moment the service can be consumed only through the API, so bulk of the time using our service will be spent dealing with the API in one way or another. Precisely, the whole process consists of composing the relevant data structures into a \"problem\" object and sending it to the server (the server uses the object to create the corresponding routing problem), making a request to the server with the object ID to queue the solution computation process, and retrieving the solution object from the server once the computation is done. These three steps are explained in more detail below:\n\n* The process starts with the construction of request object and making a POST request with the object to the server (`/routing/request`). The object's schema is outlined in the corresponding page in Routing API section. When the server receives the request, it creates a problem object using the data in the request body and responds back with the ID of the new object. Optionally, you can confirm that the server correctly created the object by making a GET request with the object's ID to `/routing/request/{requestId}`. \n\n* With the ID you received from the server in the first step, you can queue the computation by making a POST request to `/routing/request/{requestId}/response`. At first, the empty solution object is created at the server as a placeholder, and the server responds back with the ID of this object. The ID works as a handle to the solution object, because the object will be populated asynchronously after the computation process terminates. If for some reason you would like to cancel the current computation at any point before it finishes, you can send a PUT request to `/routing/response/{responseId}/status` to update the status. As this process can be quite long depending on the size of the problem, you can either periodically poll the server (GET request to `/routing/response/{responseId}/status`) for the computation status, or provide a callback URL when you make a request so that the server can notify the termination of the process. If the computation terminated unsuccessfully due to an error, it will respond with the reason for the failure. \n\n* When either the status of the computation changes to *DONE* or when you receive a callback, you can issue a GET request to `/routing/response/{responseId}` with the provided handle, and the server will respond with the associated solution object. \n\n# The Problem and Solution Object\nSince the exact schema of these objects are explained in the API section, their schema won't be explained in full here. Briefly, the \"problem\" object consists of drivers, jobs, hard constraints, soft constraints and routing configuration. Routing configuration specifies which GIS to use for calculating time and distance, where the depot, if applicable, is located, and whether vehicles return to the depot when drivers finish their jobs. GIS should follow the structure:\n \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"type\\\": \\\"name of the GIS\\\",\\n  \\\"param1\\\": \\\"the value of the first parameter if it exists\\\",\\n  \\\"param2\\\": ...,\\n  ...\\n}\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nCurrently, there are 4 available GIS:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"GIS name\",\n    \"h-1\": \"Description\",\n    \"h-2\": \"Parameters\",\n    \"0-0\": \"EuclideanGIS\",\n    \"0-1\": \"- The locations are points on Cartesian plane.\\n- Euclidean distance is used for calculating distance between two points.\\n- Time is simply distance / speed.\",\n    \"0-2\": \"\",\n    \"1-0\": \"SimpleGIS\",\n    \"1-1\": \"- Lat / Lng based GIS.\\n- Distance between two points is approximated by calculating the straight distance and multiplying a constant that accounts for the difference.\\n- Time is also distance / speed\\n- Unit is **m** for distance,  **km/h** for speed and **s** for time.\",\n    \"1-2\": \"- drivingFactor (default = 1.26)\\n- averageSpeed (default = 40)\",\n    \"2-0\": \"PreciseGIS\",\n    \"2-1\": \"Same as SimpleGIS, but distance is calculated using Haversine formula instead of naive Euclidean approximation.\",\n    \"2-2\": \"- drivingFactor\\n- averageSpeed\",\n    \"3-0\": \"LongShortGIS\",\n    \"3-1\": \"Also same as SimpleGIS, but there is a distance threshold that determines if it they are long or short, and two different drivingFactor/averageSpeed sets are used for calculating distance and time.\",\n    \"3-2\": \"- shortDrivingFactor\\n- shortAverageSpeed\\n- longDrivingFactor\\n- longAverageSpeed\\n- distanceCriteria (default = 10000)\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\nIn addition to those attributes, route rule configuration can optionally be specified. The configuration object contains ruleCode and ruleWeight, where ruleCode is an ID of the mined rule returned from calling `/mining` endpoint, and ruleWeight determines how much the rule should be accounted for the solution. For further information about problem object, refer to the relevant pages in API section.\n\nThe \"response\" object consists of its ID, the ID of the problem object that corresponds to the solution, the status of the computation, the solution to the problem, timestamp and the configurations used for this computation. The most important of these is the solution object, as it contains the routing information. The object consists of the problem that the solution is for, and the set of computed routes. The routing plan, or ordered tasks assigned to a driver, is in the \"tasks\" object in each of the route. More details about the exact schema of these objects can be found at the \"Data Schema\" section and relevant pages in API documentation.","excerpt":"This page contains instructions on constructing a request object, using API and interpreting server's response.","slug":"problem-and-solution","type":"basic","title":"Constructing a Problem, and Interpreting the Solution"}

Constructing a Problem, and Interpreting the Solution

This page contains instructions on constructing a request object, using API and interpreting server's response.

# The Workflow As mentioned earlier, at the moment the service can be consumed only through the API, so bulk of the time using our service will be spent dealing with the API in one way or another. Precisely, the whole process consists of composing the relevant data structures into a "problem" object and sending it to the server (the server uses the object to create the corresponding routing problem), making a request to the server with the object ID to queue the solution computation process, and retrieving the solution object from the server once the computation is done. These three steps are explained in more detail below: * The process starts with the construction of request object and making a POST request with the object to the server (`/routing/request`). The object's schema is outlined in the corresponding page in Routing API section. When the server receives the request, it creates a problem object using the data in the request body and responds back with the ID of the new object. Optionally, you can confirm that the server correctly created the object by making a GET request with the object's ID to `/routing/request/{requestId}`. * With the ID you received from the server in the first step, you can queue the computation by making a POST request to `/routing/request/{requestId}/response`. At first, the empty solution object is created at the server as a placeholder, and the server responds back with the ID of this object. The ID works as a handle to the solution object, because the object will be populated asynchronously after the computation process terminates. If for some reason you would like to cancel the current computation at any point before it finishes, you can send a PUT request to `/routing/response/{responseId}/status` to update the status. As this process can be quite long depending on the size of the problem, you can either periodically poll the server (GET request to `/routing/response/{responseId}/status`) for the computation status, or provide a callback URL when you make a request so that the server can notify the termination of the process. If the computation terminated unsuccessfully due to an error, it will respond with the reason for the failure. * When either the status of the computation changes to *DONE* or when you receive a callback, you can issue a GET request to `/routing/response/{responseId}` with the provided handle, and the server will respond with the associated solution object. # The Problem and Solution Object Since the exact schema of these objects are explained in the API section, their schema won't be explained in full here. Briefly, the "problem" object consists of drivers, jobs, hard constraints, soft constraints and routing configuration. Routing configuration specifies which GIS to use for calculating time and distance, where the depot, if applicable, is located, and whether vehicles return to the depot when drivers finish their jobs. GIS should follow the structure: [block:code] { "codes": [ { "code": "{\n \"type\": \"name of the GIS\",\n \"param1\": \"the value of the first parameter if it exists\",\n \"param2\": ...,\n ...\n}", "language": "json" } ] } [/block] Currently, there are 4 available GIS: [block:parameters] { "data": { "h-0": "GIS name", "h-1": "Description", "h-2": "Parameters", "0-0": "EuclideanGIS", "0-1": "- The locations are points on Cartesian plane.\n- Euclidean distance is used for calculating distance between two points.\n- Time is simply distance / speed.", "0-2": "", "1-0": "SimpleGIS", "1-1": "- Lat / Lng based GIS.\n- Distance between two points is approximated by calculating the straight distance and multiplying a constant that accounts for the difference.\n- Time is also distance / speed\n- Unit is **m** for distance, **km/h** for speed and **s** for time.", "1-2": "- drivingFactor (default = 1.26)\n- averageSpeed (default = 40)", "2-0": "PreciseGIS", "2-1": "Same as SimpleGIS, but distance is calculated using Haversine formula instead of naive Euclidean approximation.", "2-2": "- drivingFactor\n- averageSpeed", "3-0": "LongShortGIS", "3-1": "Also same as SimpleGIS, but there is a distance threshold that determines if it they are long or short, and two different drivingFactor/averageSpeed sets are used for calculating distance and time.", "3-2": "- shortDrivingFactor\n- shortAverageSpeed\n- longDrivingFactor\n- longAverageSpeed\n- distanceCriteria (default = 10000)" }, "cols": 3, "rows": 4 } [/block] In addition to those attributes, route rule configuration can optionally be specified. The configuration object contains ruleCode and ruleWeight, where ruleCode is an ID of the mined rule returned from calling `/mining` endpoint, and ruleWeight determines how much the rule should be accounted for the solution. For further information about problem object, refer to the relevant pages in API section. The "response" object consists of its ID, the ID of the problem object that corresponds to the solution, the status of the computation, the solution to the problem, timestamp and the configurations used for this computation. The most important of these is the solution object, as it contains the routing information. The object consists of the problem that the solution is for, and the set of computed routes. The routing plan, or ordered tasks assigned to a driver, is in the "tasks" object in each of the route. More details about the exact schema of these objects can be found at the "Data Schema" section and relevant pages in API documentation.