-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
139 lines (113 loc) · 4.3 KB
/
main.php
File metadata and controls
139 lines (113 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
include_once("stations.php");
include_once('bdd.php');
include_once("classes.php");
include_once("functions.php");
include_once("geometry.php");
include_once('change_projection.php');
//////////////////////////////////////////////////////
//
// Chargement des entrées
//
//////////////////////////////////////////////////////
$bdd = get_bdd();
// Projection de WGS84 vers Lambert93 des coordonnées des adresses de départ et d'arrivée
$start_WGS84=array("lat"=>$_POST['ilat'],"lng"=>$_POST['ilng']);
$project_start_node = from_WGS_to_L93($_POST['ilng'],$_POST['ilat']);
$start_x = $project_start_node->toArray()[0];
$start_y = $project_start_node->toArray()[1];
$finish_WGS84=array("lat"=>$_POST['jlat'],"lng"=>$_POST['jlng']);
$project_finish_node = from_WGS_to_L93($_POST['jlng'],$_POST['jlat']);
$finish_x = $project_finish_node->toArray()[0];
$finish_y = $project_finish_node->toArray()[1];
//récuperer la capacité totale de la batterie du véhicule dans la BDD
$car_model=$_POST['VE'];
$battery_capacity=get_car_battery_capacity($car_model,$bdd);
//Passer d'énergies en pourcentages à des énergies en kWh
$Ei = ($_POST['startEnergyInName']*$battery_capacity)/100.0;
$Ej = ($_POST['endEnergyInName']*$battery_capacity)/100.0;
$delta = 20000; // 20km
// trouver les noeuds du graphe les plus proches du départ et de l'arrivée
$start = findNearestNode($start_x, $start_y, $bdd, $delta);
$finish = findNearestNode($finish_x, $finish_y, $bdd, $delta);
//Récupérer les noeuds et arcs du graphe dans la BDD
$bestAmount = 3;
$g = new Graph();
$g->get_graph_from_bdd($start,$finish,$delta,$bdd);
$astar = new Astar($g);
//////////////////////////////////////////////////////
//
// Itinéraire
//
//////////////////////////////////////////////////////
$result = null;
$waypoints = array();//Coordonnées des étapes du trajet
$stats = array();//Statistiques du trajet
// Calcul avec 0 stations
$result = best_path_through_stations($start, $finish, $Ei, $Ej, $battery_capacity);
if($result != null)
{
$waypoints = array($start_WGS84,$finish_WGS84);
$stats = array('distance'=>$result['length'],'energy'=>$result['end_energy'],'time'=>$result['time'],'nbStations'=>0);
}
else
{
//récupérer les stations de la zone de calcul dans la BDD
$stations = generateStations($start, $finish, $delta, $bdd);
$n = 1;
$bestPaths = array();
while ($n <= 4 && count($bestPaths) == 0)
{
// Should not be done for small area
// Only large area
//simplifyStations();
//Recherche des n meilleures stations
$bestStations = bestStations($n, $start, $finish, $stations, $bestAmount);
$nbPathsStations = count($bestStations);
$bestPaths = array();
// On calcule tous les chemins
for ($i = 0; $i < $nbPathsStations; $i++)
{
$nodeStations=array();
foreach ($bestStations[$i] as $key => $value)
{
//Les éléments du tableau $bestStations[$i] sont des id de stations
//On récupère les noeuds du graphe correspondant à ces id
//et on les stocke dans le tableau $nodeStations
$nodeStations[] = $g->find_node_in_graph($value);
}
//Calcul du chemin optimal passant par les stations du tableau nodeStations
$bestPaths[$i] = best_path_through_stations($start, $finish, $Ei, $Ej, $battery_capacity, $nodeStations);
if ($bestPaths[$i] == null)
{
//Les chemins impossibles à effectuer par le véhicule sont supprimés du tableau bestPaths
unset($bestPaths[$i]);
}
}
$n++;
}
$bestPaths = array_values($bestPaths);
$nbValidPaths = count($bestPaths);
if ($nbValidPaths > 0)
{
// On tri les chemins par ordre de travel time croissant
usort($bestPaths, function($a, $b)
{
if ($a['time'] == $b['time'])
{
return 0;
}
return ($a['time'] < $b['time']) ? -1 : 1;
});
//Waypoints contient les coordonnées WGS84 de toutes les étapes du trajet.
//Stats contient les données du trajet.
//waypoints et stats sont envoyés à la page Web result.php dans laquelle sont affichés l'itinéraire et ses statistiques
$waypoints = array_merge_recursive(array($start_WGS84),get_waypoints($bestPaths[0]['path'],$bdd),array($finish_WGS84));
$stats = array('distance'=>$bestPaths[0]['length'],'energy'=>$bestPaths[0]['end_energy'],'time'=>$bestPaths[0]['time'],'nbStations'=>$n);
}
else
{
print("<p><br/><br/><br/><br/>THERE IS NO PATH MATCHING WITH THE GIVEN PARAMETERS.</p>");
}
}
?>