2 Commits
4.0.0 ... main

Author SHA1 Message Date
21f12ea924 - VERSION 5.07.31
- Se corrigio un error cuando no se mandaba el parametro "f" (final)
2025-07-31 13:18:32 -06:00
22f3166c3a -VERSION 5.07.31
- Se corrigió un error cuando no se mandaba el parametro "f" (final)
2025-07-31 13:17:12 -06:00
3 changed files with 103 additions and 118 deletions

View File

@@ -1,51 +1,31 @@
AppType=StandardJava AppType=StandardJava
Build1=Default,b4j.example Build1=Default,b4j.example
File1=config.js
File2=cover.png
File3=genetic-algorithm.js
File4=index.html
File5=LICENSE
File6=map.js
File7=README.md
File8=result.html
File9=style.css
FileGroup1=Default Group
FileGroup2=Default Group
FileGroup3=Default Group
FileGroup4=Default Group
FileGroup5=Default Group
FileGroup6=Default Group
FileGroup7=Default Group
FileGroup8=Default Group
FileGroup9=Default Group
Group=Default Group Group=Default Group
Library1=byteconverter Library1=compressstrings
Library10=nhcalculatehash Library10=byteconverter
Library11=javaobject Library2=jcore
Library2=compressstrings Library3=jfx
Library3=jcore Library4=jokhttputils2
Library4=jfx Library5=jrandomaccessfile
Library5=jokhttputils2 Library6=jserver
Library6=jrandomaccessfile Library7=json
Library7=jserver Library8=jsql
Library8=json Library9=nhcalculatehash
Library9=jsql Module1=DBRequestManager
Module1=Ayuda Module2=delDB
Module2=DBRequestManager Module3=Mapa
Module3=delDB Module4=rutaCompleta
Module4=Genetic_Algorithm Module5=Ruteador
Module5=Mapa NumberOfFiles=0
Module6=rutaCompleta NumberOfLibraries=10
Module7=Ruteador NumberOfModules=5
NumberOfFiles=9 Version=10.3
NumberOfLibraries=11
NumberOfModules=7
Version=10
@EndOfDesignText@ @EndOfDesignText@
#Region Project Attributes #Region Project Attributes
#CommandLineArgs: #CommandLineArgs:
#MergeLibraries: True #MergeLibraries: True
#AdditionalJar: sqlite-jdbc-3.7.2.jar #AdditionalJar: sqlite-jdbc-3.7.2.jar
' VERSION 5.07.31
'########################################################################################################### '###########################################################################################################
'###################### PULL ############################################################# '###################### PULL #############################################################
'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=git&Args=pull 'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=git&Args=pull
@@ -58,8 +38,9 @@ Version=10
'########################################################################################################### '###########################################################################################################
#End Region #End Region
Sub Process_Globals Sub Process_Globals
Dim srvr As Server Private srvr As Server
Dim db As SQL Dim db As SQL
' Dim fx As JFX ' Dim fx As JFX
Dim punteoLista As List Dim punteoLista As List
@@ -73,7 +54,6 @@ Sub Process_Globals
' Dim estePunto() As String ' Dim estePunto() As String
Dim error As String = "" Dim error As String = ""
Dim msg As String = "" Dim msg As String = ""
Dim hash As String = ""
End Sub End Sub
Sub AppStart (Args() As String) Sub AppStart (Args() As String)
@@ -94,7 +74,9 @@ Sub AppStart (Args() As String)
End If End If
Next Next
End If End If
' Log($"ARGS=${DBRIp}:${DBRPort}"$) ' Log($"ARGS=${DBRIp}:${DBRPort}"$)
Log("Server Port=" & srvr.Port) Log("Server Port=" & srvr.Port)
ts.Initialize ts.Initialize
@@ -105,20 +87,12 @@ Sub AppStart (Args() As String)
srvr.AddHandler("/mapa", "Mapa", False) srvr.AddHandler("/mapa", "Mapa", False)
srvr.AddHandler("/rutacompleta", "rutaCompleta", False) srvr.AddHandler("/rutacompleta", "rutaCompleta", False)
srvr.AddHandler("/borrar", "delDB", False) srvr.AddHandler("/borrar", "delDB", False)
srvr.AddHandler("/ayuda", "Ayuda", False)
srvr.AddHandler("/help", "Ayuda", False)
srvr.AddHandler("/h", "Ayuda", False)
srvr.AddHandler("/ga", "Genetic_Algorithm", False)
Log(File.ListFiles(File.DirApp))
Dim jo As JavaObject = srvr
jo.GetFieldJO("context").RunMethodJO("getMimeTypes", Null).RunMethod("addMimeMapping", Array("kml", "text/xml"))
srvr.Start srvr.Start
StartMessageLoop StartMessageLoop
'open browser and navigate to: http://127.0.0.1:51042/ 'open browser and navigate to: http://127.0.0.1:51042/
End Sub End Sub
#Region Shared Files #Region Shared Files
@@ -181,7 +155,7 @@ Sub creaTablas(params As Map)
Log(params) Log(params)
Private almacen As String = params.Get("almacen") Private almacen As String = params.Get("almacen")
Private estasCoords As String = params.Get("coords") Private estasCoords As String = params.Get("coords")
hash = params.Get("hash") Private hash As String = params.Get("hash")
Private ruta As String = $"${params.Get("ruta")}A${almacen}_${hash}"$ Private ruta As String = $"${params.Get("ruta")}A${almacen}_${hash}"$
db.BeginTransaction db.BeginTransaction
Try Try
@@ -191,7 +165,6 @@ Sub creaTablas(params As Map)
db.ExecNonQuery($"drop table if exists ${ruta}_matrizOSRM"$) db.ExecNonQuery($"drop table if exists ${ruta}_matrizOSRM"$)
' Log($"drop table if exists ${ruta}_puntos"$) ' Log($"drop table if exists ${ruta}_puntos"$)
db.ExecNonQuery($"drop table if exists ${ruta}_puntos"$) db.ExecNonQuery($"drop table if exists ${ruta}_puntos"$)
db.ExecNonQuery($"create table if not exists ${ruta}_puntos (id TEXT, nombre TEXT, lat TEXT, lon TEXT)"$) db.ExecNonQuery($"create table if not exists ${ruta}_puntos (id TEXT, nombre TEXT, lat TEXT, lon TEXT)"$)
' Log($"create table if not exists ${ruta}_puntos (id TEXT, nombre TEXT, lat TEXT, lon TEXT)"$) ' Log($"create table if not exists ${ruta}_puntos (id TEXT, nombre TEXT, lat TEXT, lon TEXT)"$)
db.ExecNonQuery($"create table if not exists ${ruta}_punteo (pos TEXT, id TEXT, nombre TEXT, lat TEXT, lon TEXT)"$) db.ExecNonQuery($"create table if not exists ${ruta}_punteo (pos TEXT, id TEXT, nombre TEXT, lat TEXT, lon TEXT)"$)
@@ -250,7 +223,10 @@ Sub generaMatrizLocal(ruta As String) 'ignore
Private lasCols, losVals As String Private lasCols, losVals As String
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$) Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$)
' Dim h As String = c.GetString("id") ' Dim h As String = c.GetString("id")
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$) If algoritmo <> 0 Then
Log($">>> insertamos el almacen en PUNTEO"$)
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
End If
' Log($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$) ' Log($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto (almacen). punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto (almacen).
Do While c.NextRow Do While c.NextRow
@@ -286,6 +262,7 @@ Sub generaMatrizOSRM(ruta As String) As ResumableSub 'ignore
' matriz = "OSRM" ' matriz = "OSRM"
punteoLista.Initialize punteoLista.Initialize
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$) Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos"$)
Log($">>> insertamos el almacen en PUNTEO"$)
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$) db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto (almacen). punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto (almacen).
Private lasCoords = "", lasCols = "idT", losIds = c.GetString("id") As String 'ignore Private lasCoords = "", lasCols = "idT", losIds = c.GetString("id") As String 'ignore
@@ -350,12 +327,14 @@ Sub ruteo(ruta As String, matriz As String) 'ignore
If checkIfTableExists(ruta&"_puntos") Then If checkIfTableExists(ruta&"_puntos") Then
db.ExecNonQuery($"delete from ${ruta}_punteo"$) db.ExecNonQuery($"delete from ${ruta}_punteo"$)
punteoLista.Initialize punteoLista.Initialize
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos limit 1"$) If algoritmo <> 0 Then
Do While c.NextRow Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos limit 1"$)
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$) Do While c.NextRow
punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto de la lista de coordenadas. Log($">>> insertamos el almacen en PUNTEO"$)
Loop db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
punteoLista.Add(c.GetString("id")) 'Lista para ruteoNearestInsertion, ponemos el primer punto de la lista de coordenadas.
Loop
End If
' Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos where id = 'CCINCIO' limit 1"$) ' Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos where id = 'CCINCIO' limit 1"$)
' Do While c.NextRow ' Do While c.NextRow
' db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$) ' db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
@@ -368,6 +347,7 @@ Sub ruteo(ruta As String, matriz As String) 'ignore
Private pf() As String = Regex.Split(",", final) ' Obtenemos id, lon y lat. Private pf() As String = Regex.Split(",", final) ' Obtenemos id, lon y lat.
Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos where id = '_${pf(0)}' limit 1"$) Private c As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos where id = '_${pf(0)}' limit 1"$)
Do While c.NextRow Do While c.NextRow
Log($">>> insertamos el almacen en PUNTEO"$)
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$) db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values ('0', '${c.GetString("id")}', 'Almacen', ${c.Getdouble("lat")}, ${c.Getdouble("lon")})"$)
Loop Loop
punteoLista.Add("_" & pf(0)) punteoLista.Add("_" & pf(0))
@@ -379,13 +359,15 @@ Sub ruteo(ruta As String, matriz As String) 'ignore
If algoritmo = 1 Then If algoritmo = 1 Then
ruteoNearestInsertion(ruta, matriz) ruteoNearestInsertion(ruta, matriz)
cualAlgoritmo = " (NI)" cualAlgoritmo = " (NI)"
Log(">>>>>>>>>> (NI)")
Else If algoritmo = 0 Then Else If algoritmo = 0 Then
Log(3) Log(">>>>>>>>>> (NN)")
ruteoNearestNeighbor(ruta, matriz) ruteoNearestNeighbor(ruta, matriz)
cualAlgoritmo = " (NN)" cualAlgoritmo = " (NN)"
Else Else
ruteoNearestInsertion2 ruteoNearestInsertion2
cualAlgoritmo = " (NI2)" cualAlgoritmo = " (NI2)"
Log(">>>>>>>>>> (NI2)")
End If End If
End If End If
End Sub End Sub
@@ -427,7 +409,7 @@ Private Sub b_tiempos_Click
' tiempos("R1") ' tiempos("R1")
End Sub End Sub
'Regresa El tiempo y distancia de la ruta especificada desde el API de OSRM. 'Regresa El tiempo y distancia de la ruta especificada.
Sub tiempos(ruta As String) As ResumableSub 'ignore Sub tiempos(ruta As String) As ResumableSub 'ignore
Log("#######################################################") Log("#######################################################")
Log("############# Main/tiempos ####################") Log("############# Main/tiempos ####################")
@@ -446,21 +428,26 @@ Sub tiempos(ruta As String) As ResumableSub 'ignore
Private d() As String Private d() As String
d = Regex.Split(";", estasCoords) d = Regex.Split(";", estasCoords)
' Log("$$$$$$ " & d.Length) ' Log("$$$$$$ " & d.Length)
Log($"http://router.project-osrm.org/route/v1/driving/${estasCoords}"$) Try
Dim j As HttpJob Log($"http://router.project-osrm.org/route/v1/driving/${estasCoords}"$)
j.Initialize("", Me) Dim j As HttpJob
j.Download($"http://router.project-osrm.org/route/v1/driving/${estasCoords}"$) j.Initialize("", Me)
Wait For (j) JobDone(j As HttpJob) j.Download($"http://router.project-osrm.org/route/v1/driving/${estasCoords}"$)
If j.Success Then Wait For (j) JobDone(j As HttpJob)
If j.Success Then
' Log("RESPONSE:") ' Log("RESPONSE:")
' Log(j.GetString) ' Log(j.GetString)
Private j0 As String = j.GetString Private j0 As String = j.GetString
Else Else
Log($"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ${CRLF} ${j.ErrorMessage}"$) Log($"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ${CRLF} ${j.ErrorMessage}"$)
If error = "" Then error = j.ErrorMessage If error = "" Then error = j.ErrorMessage
Log($"######################### ${error}"$) Log($"######################### ${error}"$)
End If End If
j.Release j.Release
Catch
Log(LastException)
End Try
' StopMessageLoop ' StopMessageLoop
Private js As JSONParser Private js As JSONParser
js.Initialize(j0) js.Initialize(j0)
@@ -483,7 +470,7 @@ Sub tiempos(ruta As String) As ResumableSub 'ignore
' Log("Distance: " & rutas.Get("distance")) ' Log("Distance: " & rutas.Get("distance"))
' Log("Legs: " & rutas.Get("legs").As(List).Size) ' Log("Legs: " & rutas.Get("legs").As(List).Size)
' Log("Waypoints: " & waypoints.Size) ' Log("Waypoints: " & waypoints.Size)
ts.Put(ruta, CreateMap("code":"OK", "hash":hash, "duration":rutas.Get("duration"), "distance":rutas.Get("distance"), "puntos":rutas.Get("legs").As(List).Size)) ts.Put(ruta, CreateMap("code":"OK", "duration":rutas.Get("duration"), "distance":rutas.Get("distance"), "puntos":rutas.Get("legs").As(List).Size))
' Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>" & ts) ' Log(">>>>>>>>>>>>>>>>>>>>>>>>>>>" & ts)
Catch Catch
Log(LastException) Log(LastException)
@@ -505,16 +492,33 @@ Sub ruteoNearestNeighbor(ruta As String, matriz As String) 'ignore
Log("####################################################################") Log("####################################################################")
Dim g As ResultSet Dim g As ResultSet
Private x As ResultSet = db.ExecQuery($"select id from ${ruta}_puntos"$) Private x As ResultSet = db.ExecQuery($"select id from ${ruta}_puntos"$)
Private cont As Int = 0
Private sqlWhere As String = ""
Do While x.NextRow 'Ejecutamos el siguiente codigo la cantidad de veces que hay puntos. Do While x.NextRow 'Ejecutamos el siguiente codigo la cantidad de veces que hay puntos.
Private punto As ResultSet = db.ExecQuery($"select id, count(id) as regs from ${ruta}_punteo order by pos DESC limit 1"$) ' Log(cont)
Do While punto.NextRow If cont = 0 Then
' Log($"Select idt, '${punto.GetString("id")}', nombre, lat, lon from R1_matriz join R1_puntos on idT = id where idT Not in (Select id from r1_punteo) order by '${punto.GetString("id")}' Asc limit 1"$) sqlWhere = $" idt = '_ACTUAL' and "$
g = db.ExecQuery($"Select idt, '${punto.GetString("id")}', nombre, lat, lon from ${ruta}_matriz${matriz} join ${ruta}_puntos on idT = id where idT Not in (Select id from ${ruta}_punteo) order by '${punto.GetString("id")}' Asc limit 1"$) Private rs As ResultSet = db.ExecQuery($"select * from ${ruta}_puntos where id = '_ACTUAL'"$)
Do While g.NextRow Do While rs.NextRow
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values (${punto.GetString("regs")}, '${g.GetString("idT")}', '${g.GetString("nombre")}', '${g.GetString("lat")}', '${g.GetString("lon")}')"$) Log(">>> Insertamos pos ACTUAL")
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values (0, '${rs.GetString("id")}', '${rs.GetString("nombre")}', '${rs.GetString("lat")}', '${rs.GetString("lon")}')"$)
Loop Loop
Else
sqlWhere = ""
End If
Private punto As ResultSet = db.ExecQuery($"select id, count(id) as regs from ${ruta}_punteo order by pos DESC limit 1"$)
' Do While punto.NextRow
' Log(punto.GetString("id"))
g = db.ExecQuery($"Select idt, "${punto.GetString("id")}", nombre, lat, lon from ${ruta}_matriz${matriz} join ${ruta}_puntos on idT = id where ${sqlWhere} idT Not in (Select id from ${ruta}_punteo) order by "${punto.GetString("id")}" Asc limit 1"$)
Log($"Select idt, "${punto.GetString("id")}", nombre, lat, lon from ${ruta}_matriz${matriz} join ${ruta}_puntos on idT = id where ${sqlWhere} idT Not in (Select id from ${ruta}_punteo) order by "${punto.GetString("id")}" Asc limit 1"$)
Do While g.NextRow
Log($">>>> insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values (${punto.GetString("regs")}, '${g.GetString("idT")}', '${g.GetString("nombre")}', '${g.GetString("lat")}', '${g.GetString("lon")}')"$)
db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values (${punto.GetString("regs")}, '${g.GetString("idT")}', '${g.GetString("nombre")}', '${g.GetString("lat")}', '${g.GetString("lon")}')"$)
Loop Loop
' Loop
cont = cont + 1
Loop Loop
' db.ExecNonQuery($"insert into ${ruta}_punteo (pos, id, nombre, lat, lon) values (${punto.GetString("regs")}, '${g.GetString("idT")}', '${g.GetString("nombre")}', '${g.GetString("lat")}', '${g.GetString("lon")}')"$)
End Sub End Sub
'Nearest Insertion 'Nearest Insertion
@@ -673,7 +677,7 @@ Public Sub calculateDistance3(lat1 As Double, lon1 As Double, lat2 As Double, lo
Return Round(Yards) Return Round(Yards)
Catch Catch
Log("CalcDistance " & LastException) Log("CalcDistance " & LastException)
If error = "" Then error = LastException if error = "" then error = LastException
Return -1 Return -1
End Try End Try
End Sub End Sub

View File

@@ -4,24 +4,18 @@ ModuleBookmarks2=
ModuleBookmarks3= ModuleBookmarks3=
ModuleBookmarks4= ModuleBookmarks4=
ModuleBookmarks5= ModuleBookmarks5=
ModuleBookmarks6=
ModuleBookmarks7=
ModuleBreakpoints0= ModuleBreakpoints0=
ModuleBreakpoints1= ModuleBreakpoints1=
ModuleBreakpoints2= ModuleBreakpoints2=
ModuleBreakpoints3= ModuleBreakpoints3=
ModuleBreakpoints4= ModuleBreakpoints4=
ModuleBreakpoints5= ModuleBreakpoints5=
ModuleBreakpoints6=
ModuleBreakpoints7=
ModuleClosedNodes0= ModuleClosedNodes0=
ModuleClosedNodes1= ModuleClosedNodes1=
ModuleClosedNodes2= ModuleClosedNodes2=
ModuleClosedNodes3= ModuleClosedNodes3=
ModuleClosedNodes4=5,6,8,9,10 ModuleClosedNodes4=
ModuleClosedNodes5= ModuleClosedNodes5=
ModuleClosedNodes6= NavigationStack=Main,ruteoNearestNeighbor,467,6,Main,generaMatrizLocal,201,6,Main,creaTablas,141,0,Main,generaMatrizOSRM,239,0,Main,ruteoNearestInsertion,567,0,Main,ruteo,336,0,Main,tiempos,406,1,Ruteador,Handle,43,6,Main,Process_Globals,28,0,Ruteador,generaMatrizRuteoTiempos,92,6,Ruteador,checkIfTableExists,228,0
ModuleClosedNodes7=6,7
NavigationStack=Ruteador,Class_Globals,9,4,Ruteador,Handle,28,0,Main,ruteoNearestNeighbor,466,0,Genetic_Algorithm,traeDistanciaDesdeMatriz,398,6,Main,Process_Globals,31,6,Main,creaTablas,143,0,Mapa,ruteoCompleto,167,4,Ruteador,generaMatrizRuteoTiempos,125,0,Ruteador,tiempos,194,0,Main,tiempos,441,4
SelectedBuild=0 SelectedBuild=0
VisibleModules=7,5,6,2,3,4,1 VisibleModules=5,3,4,1,2

View File

@@ -14,7 +14,6 @@ Sub Class_Globals
Dim getHash As CalculateHash Dim getHash As CalculateHash
Dim js As JSONGenerator Dim js As JSONGenerator
Dim cuantosPuntos As Int = 0 Dim cuantosPuntos As Int = 0
Dim elHash As String
End Sub End Sub
Public Sub Initialize Public Sub Initialize
@@ -32,32 +31,23 @@ Sub Handle(req As ServletRequest, resp As ServletResponse)
Log("##############################################################") Log("##############################################################")
' Log("q='"&req.GetParameter("q")&"'") ' Log("q='"&req.GetParameter("q")&"'")
' Log($"REQ: ${req.FullRequestURI}"$) ' Log($"REQ: ${req.FullRequestURI}"$)
elHash = getHash.CalculateTheHash(req.FullRequestURI) Private elHash As String = getHash.CalculateTheHash(req.FullRequestURI)
' Log(elHash) ' Log(elHash)
Private ruta As String = req.GetParameter("r") Private ruta As String = req.GetParameter("r")
Private almacen As String = req.GetParameter("a") Private almacen As String = req.GetParameter("a")
Private coords As String = req.GetParameter("c") Private coords As String = req.GetParameter("c")
Private matriz As String = req.GetParameter("m") Private matriz As String = req.GetParameter("m")
Private ayuda As String Main.algoritmo = 1
If req.GetParameter("h") <> "" Then ayuda = req.GetParameter("h") If req.GetParameter("algoritmo") = "0" Or req.GetParameter("algoritmo") = "NN" Then
If req.GetParameter("h") <> "" Then ayuda = req.GetParameter("help") Main.algoritmo = 0 ' Algoritmo = Nearest Neighbor.
If req.GetParameter("h") <> "" Then ayuda = req.GetParameter("ayuda") End If
Main.inicio = req.GetParameter("i") Main.inicio = req.GetParameter("i")
Main.final = req.GetParameter("f") Main.final = req.GetParameter("f")
If matriz <> "" And matriz <> "OSRM" Then matriz = "" If matriz <> "" And matriz <> "OSRM" Then matriz = ""
' Log($"r: ${ruta}, a: ${almacen}, Coords: ${coords}"$) ' Log($"r: ${ruta}, a: ${almacen}, Coords: ${coords}"$)
Private urlParams As Map Private urlParams As Map
Log("|"&ayuda&"|"& req.GetParameter("h") & "|" ) If ruta <> "" And almacen <> "" And coords <> "" Then
If ayuda <> "" Then If Main.final <> "" And Main.algoritmo <> 0 Then coords = coords & ";" & Main.final
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 ruta = "R" & ruta
urlParams.Initialize urlParams.Initialize
urlParams.Put("almacen", almacen) urlParams.Put("almacen", almacen)
@@ -111,6 +101,10 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
End Try End Try
'Generamos el ruteo 'Generamos el ruteo
Main.ruteo($"${r}"$, matriz) Main.ruteo($"${r}"$, matriz)
If Main.algoritmo <> 0 And Main.final <> "" Then
Private t() As String = Regex.Split(",", Main.final)
Main.db.ExecNonQuery($"insert into ${r}_punteo (pos, id, nombre, lat, lon) values (${cuantosPuntos + 1}, '${t(0)}', 'almacen', '${t(2)}', '${t(1)}')"$)
End If
Wait for(Main.tiempos($"${r}"$)) Complete (Result As Int) Wait for(Main.tiempos($"${r}"$)) Complete (Result As Int)
Private ts As Map = Main.ts.Get($"${r}"$) Private ts As Map = Main.ts.Get($"${r}"$)
' Log(ts) ' Log(ts)
@@ -129,7 +123,6 @@ Sub generaMatrizRuteoTiempos(r As String, resp As ServletResponse, ruta As Strin
If matriz = "" Then tempMap.Put("api", "Local") 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. '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("code", "OK")
tempMap.Put("hash", elHash)
tempMap.Put("ruta", ruta) tempMap.Put("ruta", ruta)
tempMap.Put("almacen", almacen) tempMap.Put("almacen", almacen)
tempMap.Put("duration", ts.Get("duration")) tempMap.Put("duration", ts.Get("duration"))
@@ -183,22 +176,18 @@ Sub tiempos(r As String, resp As ServletResponse, ruta As String, almacen As Str
Private listCoords As List Private listCoords As List
listCoords.Initialize listCoords.Initialize
Private coords2 As String = "" Private coords2 As String = ""
Private coords3 As String = ""
Do While p.NextRow Do While p.NextRow
listCoords.Add(CreateMap("pos":p.GetString("pos"), "id":p.GetString("id"), "lat":p.GetString("lat"), "lon":p.GetString("lon"))) listCoords.Add(CreateMap("pos":p.GetString("pos"), "id":p.GetString("id"), "lat":p.GetString("lat"), "lon":p.GetString("lon")))
If coords2 = "" Then If coords2 = "" Then
coords2 = $"${p.GetString("lon")},${p.GetString("lat")}"$ coords2 = $"${p.GetString("lon")},${p.GetString("lat")}"$
coords3 = $"${p.GetString("id")},${p.GetString("lon")},${p.GetString("lat")}"$
Else Else
coords2 = $"${coords2}:${p.GetString("lon")},${p.GetString("lat")}"$ coords2 = $"${coords2}:${p.GetString("lon")},${p.GetString("lat")}"$
coords3 = $"${coords3};${p.GetString("id")},${p.GetString("lon")},${p.GetString("lat")}"$
End If End If
Loop Loop
Main.db.Close Main.db.Close
tempMap.Put("api", matriz) tempMap.Put("api", matriz)
If matriz = "" Then tempMap.Put("api", "Local") If matriz = "" Then tempMap.Put("api", "Local")
tempMap.Put("code", "OK") tempMap.Put("code", "OK")
tempMap.Put("hash", elHash)
tempMap.Put("ruta", ruta) tempMap.Put("ruta", ruta)
tempMap.Put("almacen", almacen) tempMap.Put("almacen", almacen)
tempMap.Put("duration", ts.Get("duration")) tempMap.Put("duration", ts.Get("duration"))
@@ -216,9 +205,7 @@ Sub tiempos(r As String, resp As ServletResponse, ruta As String, almacen As Str
resp.ContentType = "text/html" resp.ContentType = "text/html"
resp.Write(js.ToString) resp.Write(js.ToString)
Log("###################################################################" & CRLF) Log("###################################################################" & CRLF)
Log($"http://keymon.lat:${Main.srvr.port}/ga?c=${coords3}"$) Log($"http://keymon.lat:9001/kmz.php?a=1&c=${coords2}"$)
Log("###################################################################" & CRLF)
Log($"http://keymon.lat:${Main.srvr.port}/kmz.php?a=1&c=${coords2}"$)
Log("###################################################################" & CRLF) Log("###################################################################" & CRLF)
Log("Liga para ver la ruta en mapa:" & 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}"$) Log($"https://osm.quelltextlich.at/viewer-js.html?kml_url=http://keymon.lat:9001/kmz.php?c=${coords2}"$)