- Cambios en el Algoritmo Genetico.

- Se agregó el HASH al JSON que regresa cuando se genera el ruteo.
This commit is contained in:
2024-05-07 05:46:32 -06:00
parent 433fc32b9a
commit b44f28abc9
18 changed files with 2353 additions and 35 deletions

View File

@@ -13,6 +13,8 @@ Sub Class_Globals
Dim m, m2 As Map
Dim getHash As CalculateHash
Dim js As JSONGenerator
Dim cuantosPuntos As Int = 0
Dim elHash As String
End Sub
Public Sub Initialize
@@ -30,18 +32,31 @@ Sub Handle(req As ServletRequest, resp As ServletResponse)
Log("##############################################################")
' Log("q='"&req.GetParameter("q")&"'")
' Log($"REQ: ${req.FullRequestURI}"$)
Private elHash As String = getHash.CalculateTheHash(req.FullRequestURI)
elHash = getHash.CalculateTheHash(req.FullRequestURI)
' Log(elHash)
Private ruta As String = req.GetParameter("r")
Private almacen As String = req.GetParameter("a")
Private coords As String = req.GetParameter("c")
Private matriz As String = req.GetParameter("m")
Private ayuda As String
If req.GetParameter("h") <> "" Then ayuda = req.GetParameter("h")
If req.GetParameter("h") <> "" Then ayuda = req.GetParameter("help")
If req.GetParameter("h") <> "" Then ayuda = req.GetParameter("ayuda")
Main.inicio = req.GetParameter("i")
Main.final = req.GetParameter("f")
If matriz <> "" And matriz <> "OSRM" Then matriz = ""
' Log($"r: ${ruta}, a: ${almacen}, Coords: ${coords}"$)
Private urlParams As Map
If ruta <> "" And almacen <> "" And coords <> "" Then
Log("|"&ayuda&"|"& req.GetParameter("h") & "|" )
If ayuda <> "" Then
resp.ContentType = "text/html"
resp.Write($"Son necesarios los siguientes parametros:<br>
* r - La ruta<br>
* a - El almacen<br>
* c - Lista de puntos (id_cliente,lon,lat) separadas por punto y coma, el primer punto de la lista, se considera el punto de INICIO de la ruta.<br>
* m - La matriz a usar LOCAL u OSRM (Opcional, default local<br>
* f - El destino final (id_cliente,lon,lat) de donde termina la ruta (Opcional)"$)
else If ruta <> "" And almacen <> "" And coords <> "" Then
If Main.final <> "" Then coords = coords & ";" & Main.final
ruta = "R" & ruta
urlParams.Initialize
@@ -77,6 +92,15 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
Log("############################################################################")
Try
'Generamos la matriz
Private p As ResultSet = Main.db.ExecQuery($"select count(id) as cuantosPuntos from ${r}_puntos"$)
Do While p.NextRow ' Revisamos que sean MENOS de 100 puntos, si no, usamos la matriz LOCAL.
cuantosPuntos = p.GetInt("cuantosPuntos")
Loop
If cuantosPuntos > 98 Then
If matriz = "OSRM" Then Main.msg = "Mas de 100 puntos, usamos matriz LOCAL"
matriz = ""
End If
Log($"#### PUNTOS: ${cuantosPuntos}"$)
If matriz = "OSRM" Then
Wait for(Main.generaMatrizOSRM(r)) Complete (Result As Int)
Else
@@ -105,6 +129,7 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
If matriz = "" Then tempMap.Put("api", "Local")
'Ponemos la ruta, almacen, tiempos, distancias y la lista de las coordenadas en un mapa para regresarla en un JSON.
tempMap.Put("code", "OK")
tempMap.Put("hash", elHash)
tempMap.Put("ruta", ruta)
tempMap.Put("almacen", almacen)
tempMap.Put("duration", ts.Get("duration"))
@@ -112,6 +137,7 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
tempMap.Put("puntos", ts.Get("puntos"))
tempMap.Put("coords", listCoords)
tempMap.Put("mensaje", Main.msg)
If Main.error <> "" Then tempMap.Put("mensaje", Main.error)
If tempMap.get("puntos") = 0 Then tempMap.Put("code", "KO")
' Log(tempMap)
js.Initialize(tempMap)
@@ -132,6 +158,7 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
tempMap.Put("puntos", 0)
tempMap.Put("coords", "")
tempMap.Put("mensaje", Main.msg)
If Main.error <> "" Then tempMap.Put("mensaje", Main.error)
' Log(tempMap)
js.Initialize(tempMap)
StopMessageLoop
@@ -156,18 +183,22 @@ Sub tiempos(r As String, resp As ServletResponse, ruta As String, almacen As Str
Private listCoords As List
listCoords.Initialize
Private coords2 As String = ""
Private coords3 As String = ""
Do While p.NextRow
listCoords.Add(CreateMap("pos":p.GetString("pos"), "id":p.GetString("id"), "lat":p.GetString("lat"), "lon":p.GetString("lon")))
If coords2 = "" Then
coords2 = $"${p.GetString("lon")},${p.GetString("lat")}"$
coords3 = $"${p.GetString("id")},${p.GetString("lon")},${p.GetString("lat")}"$
Else
coords2 = $"${coords2}:${p.GetString("lon")},${p.GetString("lat")}"$
coords3 = $"${coords3};${p.GetString("id")},${p.GetString("lon")},${p.GetString("lat")}"$
End If
Loop
Main.db.Close
tempMap.Put("api", matriz)
If matriz = "" Then tempMap.Put("api", "Local")
tempMap.Put("code", "OK")
tempMap.Put("hash", elHash)
tempMap.Put("ruta", ruta)
tempMap.Put("almacen", almacen)
tempMap.Put("duration", ts.Get("duration"))
@@ -175,6 +206,7 @@ Sub tiempos(r As String, resp As ServletResponse, ruta As String, almacen As Str
tempMap.Put("puntos", ts.Get("puntos"))
tempMap.Put("coords", listCoords)
tempMap.Put("mensaje", Main.msg)
If Main.error <> "" Then tempMap.Put("mensaje", Main.error)
If tempMap.get("puntos") = 0 Then tempMap.Put("code", "KO")
' Log(tempMap)
js.Initialize(tempMap)
@@ -184,7 +216,9 @@ Sub tiempos(r As String, resp As ServletResponse, ruta As String, almacen As Str
resp.ContentType = "text/html"
resp.Write(js.ToString)
Log("###################################################################" & CRLF)
Log($"http://keymon.lat:9001/kmz.php?a=1&c=${coords2}"$)
Log($"http://keymon.lat:${Main.srvr.port}/ga?c=${coords3}"$)
Log("###################################################################" & CRLF)
Log($"http://keymon.lat:${Main.srvr.port}/kmz.php?a=1&c=${coords2}"$)
Log("###################################################################" & CRLF)
Log("Liga para ver la ruta en mapa:" & CRLF)
Log($"https://osm.quelltextlich.at/viewer-js.html?kml_url=http://keymon.lat:9001/kmz.php?c=${coords2}"$)