1 |
package dk.daoas.fulddaekning.osrm; |
package dk.daoas.fulddaekning.osrm; |
2 |
|
|
3 |
import java.io.IOException; |
import java.io.IOException; |
|
import java.util.ArrayList; |
|
4 |
import java.util.Collection; |
import java.util.Collection; |
|
import java.util.Iterator; |
|
|
import java.util.List; |
|
|
import java.util.concurrent.Future; |
|
5 |
import java.util.logging.Level; |
import java.util.logging.Level; |
6 |
import java.util.logging.Logger; |
import java.util.logging.Logger; |
7 |
|
|
8 |
|
import net.minidev.json.JSONValue; |
9 |
|
|
10 |
import org.apache.http.HttpEntity; |
import org.apache.http.HttpEntity; |
|
import org.apache.http.HttpHost; |
|
|
import org.apache.http.HttpRequest; |
|
11 |
import org.apache.http.HttpResponse; |
import org.apache.http.HttpResponse; |
12 |
import org.apache.http.client.ClientProtocolException; |
import org.apache.http.client.ClientProtocolException; |
13 |
import org.apache.http.client.ResponseHandler; |
import org.apache.http.client.ResponseHandler; |
14 |
import org.apache.http.client.methods.HttpGet; |
import org.apache.http.client.methods.HttpGet; |
15 |
import org.apache.http.impl.client.CloseableHttpClient; |
import org.apache.http.impl.client.CloseableHttpClient; |
16 |
import org.apache.http.impl.client.HttpClients; |
import org.apache.http.impl.client.HttpClients; |
|
import org.apache.http.impl.nio.client.CloseableHttpPipeliningClient; |
|
|
import org.apache.http.impl.nio.client.HttpAsyncClients; |
|
17 |
import org.apache.http.util.EntityUtils; |
import org.apache.http.util.EntityUtils; |
18 |
|
|
19 |
import com.google.gson.Gson; |
import com.google.gson.Gson; |
37 |
|
|
38 |
//static OSRMBinding binding = null; |
//static OSRMBinding binding = null; |
39 |
|
|
40 |
//final String host = "127.0.0.1"; |
final String host = "127.0.0.1"; |
41 |
final String host = "10.30.2.103"; |
//final String host = "10.30.2.103"; |
42 |
final int port = 5000; |
final int port = 5000; |
43 |
final String base_url = "http://" + host + ":" + port; |
final String base_url = "http://" + host + ":" + port; |
44 |
/* |
/* |
67 |
|
|
68 |
try { |
try { |
69 |
String txtResponse = HttpUtil.getContentString(sb.toString(), 500, "UTF-8"); |
String txtResponse = HttpUtil.getContentString(sb.toString(), 500, "UTF-8"); |
70 |
OSRMDistanceTable table = gson.fromJson(txtResponse, OSRMDistanceTable.class); |
//OSRMDistanceTable table = gson.fromJson(txtResponse, OSRMDistanceTable.class); |
71 |
|
OSRMDistanceTable table = JSONValue.parse(txtResponse, OSRMDistanceTable.class); |
72 |
if (table.status != 0) { |
if (table.status != 0) { |
73 |
logger.info("OSRM failed with message: " + table.status_message); |
logger.info("OSRM failed with message: " + table.status_message); |
74 |
return null; |
return null; |
75 |
} |
} |
76 |
|
|
77 |
|
if ( table.distance_table.length != (hayArray.length + 1) ) { |
78 |
|
logger.log(Level.SEVERE, "Wrong number of results in matrix " + table.distance_table.length); |
79 |
|
System.exit(0); |
80 |
|
} |
81 |
|
|
82 |
int bedsteTid = Integer.MAX_VALUE; |
int bedsteTid = Integer.MAX_VALUE; |
83 |
|
|
84 |
for (int i = 1; i<table.distance_table.length; i++) { |
for (int i = 1; i<table.distance_table.length; i++) { |
125 |
|
|
126 |
try { |
try { |
127 |
float distance_table[][] = binding.table( points ); |
float distance_table[][] = binding.table( points ); |
128 |
|
|
129 |
|
if ( distance_table.length != (hayArray.length + 1) ) { |
130 |
|
logger.log(Level.SEVERE, "Wrong number of results in matrix " + distance_table.length); |
131 |
|
System.exit(0); |
132 |
|
} |
133 |
|
|
134 |
int bedsteTid = Integer.MAX_VALUE; |
int bedsteTid = Integer.MAX_VALUE; |
135 |
|
|