Skip to content
Snippets Groups Projects
Commit eb3625fe authored by julienpillis's avatar julienpillis
Browse files

ajout commentaires

parent 6850da20
No related branches found
No related tags found
2 merge requests!7Main,!6Signalisation
......@@ -87,7 +87,7 @@ func (ag *Agent) Start() {
ag.behavior.Deliberate(ag)
ag.behavior.Act(ag)
ag.syncChan <- step
if ag.decision == Disapear{
if ag.decision == Disapear {
ag.env.RemoveAgent(*ag)
return
}
......@@ -250,8 +250,9 @@ func (ag *Agent) MoveAgent() {
}
func (ag *Agent) generatePathExtremities() (alg.Node, alg.Node) {
// Génère les points extrêmes du chemin de l'agent
start := *alg.NewNode(ag.position[0], ag.position[1], 0, 0, ag.width, ag.height)
destination := ag.findDestination()
destination := ag.destination
end := *alg.NewNode(destination[0], destination[1], 0, 0, ag.width, ag.height)
return start, end
}
......@@ -305,6 +306,7 @@ func removeCoord(to_remove Coord, mapping map[Coord]string) {
}
func equalCoord(coord1, coord2 *Coord) bool {
// Vérifie l'égalité de 2 objets Coord
return coord1[0] == coord2[0] && coord1[1] == coord2[1]
}
......@@ -313,69 +315,6 @@ func rotateAgent(agt *Agent, orientation int) {
agt.orientation = orientation
}
// Fonction de recherche du prochain point de destination
func (ag *Agent) findDestination() Coord {
// destination := ag.destination
// destinationZone := ag.env.zones[ag.destination]
// if destinationZone != ag.env.zones[ag.position] {
// // Si on n'est pas dans la zone de la destination, on va s'orienter par un panneau
// for _, panneau := range ag.env.panneaux[destinationZone] {
// if !ag.visitedPanneaux[panneau] {
// // Si le panneau n'a pas été visité et que son heuristique est meilleure
// if equalCoord(&ag.position, &Coord{ag.visiting.Row(), ag.visiting.Col()}) {
// ag.visiting = &panneau
// } else if panneau.Heuristic() < ag.visiting.Heuristic() {
// if HeuristicWithObstacles(ag.position, Coord{panneau.Row(), panneau.Col()}, ag.env) < HeuristicWithObstacles(ag.position, Coord{ag.visiting.Row(), ag.visiting.Col()}, ag.env) {
// //TODO:revoir la mise à jour, peut-être à faire lorsqu'on se situe au niveau de panneau, pas avant
// ag.visiting = &panneau
// }
// }
// }
// fmt.Println(ag.visiting)
// }
// }
// destination = Coord{ag.visiting.Row(), ag.visiting.Col()}
// if !equalCoord(&destination, &ag.destination) {
// // Si la visite de panneau est prévue, on met à jour les informations nécessaires
// ag.visitedPanneaux[*ag.visiting] = true
// }
// return destination
//best_panneau := alg.NewNode(ag.destination[0], ag.destination[1], 0, HeuristicWithObstacles(ag.position, ag.destination, ag.env))
//destinationZone := ag.env.zones[ag.destination]
//max_dist := best_panneau.Heuristic()
// for _, panneau := range ag.env.panneaux[destinationZone] {
// // Le panneau ne doit pas être déjà visité, et doit avoir une heuristique meilleure
// if !ag.visitedPanneaux[panneau] && panneau.Heuristic() < best_panneau.Heuristic() {
// best_panneau = &panneau
// }
// }
//return Coord{best_panneau.Row(), best_panneau.Col()}
return ag.destination
}
// Heuristique pour findDestination
func HeuristicWithObstacles(x, y Coord, env *Environment) int {
// Heuristique de distance de Manhattan
distance := alg.Heuristic(x[0], x[1], *alg.NewNode(y[0], y[1], 0, 0, 0, 0))
// Compte le nombre d'obstacles sur le chemin
obstaclePenality := 0
for i := min(x[0], x[1]); i <= max(x[0], x[1]); i++ {
for j := min(y[0], y[1]); j <= max(y[0], y[1]); j++ {
if i >= 0 && i < len(env.station) && j >= 0 && j < len(env.station[0]) && env.station[i][j] == "Q" || env.station[i][j] == "X" {
obstaclePenality = obstaclePenality + 10
}
}
}
// Retourne valeur de l'heurisitique
return distance + obstaclePenality
}
func calculateBounds(position Coord, width, height, orientation int) (infRow, supRow, infCol, supCol int) {
// Fonction de génération des frontières d'un objet ayant une largeur et une hauteur, en focntion de son orientation
borneInfRow := 0
......
......@@ -3,9 +3,6 @@ package simulation
import (
"fmt"
"log"
//"math/rand"
alg "metrosim/internal/algorithms"
"sync"
"time"
)
......@@ -43,57 +40,6 @@ var carte [20][20]string = [20][20]string{
{"X", "X", "X", "X", "S", "S", "X", "X", "X", "X", "X", "X", "E", "E", "X", "X", "X", "X", "X", "X"},
}
var zonesCarte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{9, 9}: 1,
{0, 10}: 2, {0, 11}: 2, {0, 12}: 2, {0, 13}: 2, {0, 14}: 2, {0, 15}: 2, {0, 16}: 2, {0, 17}: 2, {0, 18}: 2, {0, 19}: 2,
{1, 10}: 2, {1, 11}: 2, {1, 12}: 2, {1, 13}: 2, {1, 14}: 2, {1, 15}: 2, {1, 16}: 2, {1, 17}: 2, {1, 18}: 2, {1, 19}: 2,
{2, 10}: 2, {2, 11}: 2, {2, 12}: 2, {2, 13}: 2, {2, 14}: 2, {2, 15}: 2, {2, 16}: 2, {2, 17}: 2, {2, 18}: 2, {2, 19}: 2,
{3, 10}: 2, {3, 11}: 2, {3, 12}: 2, {3, 13}: 2, {3, 14}: 2, {3, 15}: 2, {3, 16}: 2, {3, 17}: 2, {3, 18}: 2, {3, 19}: 2,
{4, 10}: 2, {4, 11}: 2, {4, 12}: 2, {4, 13}: 2, {4, 14}: 2, {4, 15}: 2, {4, 16}: 2, {4, 17}: 2, {4, 18}: 2, {4, 19}: 2,
{5, 10}: 2, {5, 11}: 2, {5, 12}: 2, {5, 13}: 2, {5, 14}: 2, {5, 15}: 2, {5, 16}: 2, {5, 17}: 2, {5, 18}: 2, {5, 19}: 2,
{6, 10}: 2, {6, 11}: 2, {6, 12}: 2, {6, 13}: 2, {6, 14}: 2, {6, 15}: 2, {6, 16}: 2, {6, 17}: 2, {6, 18}: 2, {6, 19}: 2,
{7, 10}: 2, {7, 11}: 2, {7, 12}: 2, {7, 13}: 2, {7, 14}: 2, {7, 15}: 2, {7, 16}: 2, {7, 17}: 2, {7, 18}: 2, {7, 19}: 2,
{8, 10}: 2, {8, 11}: 2, {8, 12}: 2, {8, 13}: 2, {8, 14}: 2, {8, 15}: 2, {8, 16}: 2, {8, 17}: 2, {8, 18}: 2, {8, 19}: 2,
{9, 10}: 2, {9, 11}: 2, {9, 12}: 2, {9, 13}: 2, {9, 14}: 2, {9, 15}: 2, {9, 16}: 2, {9, 17}: 2, {9, 18}: 2, {9, 19}: 2,
{10, 0}: 3, {10, 1}: 3, {10, 2}: 3, {10, 3}: 3, {10, 4}: 3, {10, 5}: 3, {10, 6}: 3, {10, 7}: 3, {10, 8}: 3, {10, 9}: 3,
{11, 0}: 3, {11, 1}: 3, {11, 2}: 3, {11, 3}: 3, {11, 4}: 3, {11, 5}: 3, {11, 6}: 3, {11, 7}: 3, {11, 8}: 3, {11, 9}: 3,
{12, 0}: 3, {12, 1}: 3, {12, 2}: 3, {12, 3}: 3, {12, 4}: 3, {12, 5}: 3, {12, 6}: 3, {12, 7}: 3, {12, 8}: 3, {12, 9}: 3,
{13, 0}: 3, {13, 1}: 3, {13, 2}: 3, {13, 3}: 3, {13, 4}: 3, {13, 5}: 3, {13, 6}: 3, {13, 7}: 3, {13, 8}: 3, {13, 9}: 3,
{14, 0}: 3, {14, 1}: 3, {14, 2}: 3, {14, 3}: 3, {14, 4}: 3, {14, 5}: 3, {14, 6}: 3, {14, 7}: 3, {14, 8}: 3, {14, 9}: 3,
{15, 0}: 3, {15, 1}: 3, {15, 2}: 3, {15, 3}: 3, {15, 4}: 3, {15, 5}: 3, {15, 6}: 3, {15, 7}: 3, {15, 8}: 3, {15, 9}: 3,
{16, 0}: 3, {16, 1}: 3, {16, 2}: 3, {16, 3}: 3, {16, 4}: 3, {16, 5}: 3, {16, 6}: 3, {16, 7}: 3, {16, 8}: 3, {16, 9}: 3,
{17, 0}: 3, {17, 1}: 3, {17, 2}: 3, {17, 3}: 3, {17, 4}: 3, {17, 5}: 3, {17, 6}: 3, {17, 7}: 3, {17, 8}: 3, {17, 9}: 3,
{18, 0}: 3, {18, 1}: 3, {18, 2}: 3, {18, 3}: 3, {18, 4}: 3, {18, 5}: 3, {18, 6}: 3, {18, 7}: 3, {18, 8}: 3, {18, 9}: 3,
{19, 0}: 3, {19, 1}: 3, {19, 2}: 3, {19, 3}: 3, {19, 4}: 3, {19, 5}: 3, {19, 6}: 3, {19, 7}: 3, {19, 8}: 3, {19, 9}: 3,
{10, 10}: 4, {10, 11}: 4, {10, 12}: 4, {10, 13}: 4, {10, 14}: 4, {10, 15}: 4, {10, 16}: 4, {10, 17}: 4, {10, 18}: 4, {10, 19}: 4,
{11, 10}: 4, {11, 11}: 4, {11, 12}: 4, {11, 13}: 4, {11, 14}: 4, {11, 15}: 4, {11, 16}: 4, {11, 17}: 4, {11, 18}: 4, {11, 19}: 4,
{12, 10}: 4, {12, 11}: 4, {12, 12}: 4, {12, 13}: 4, {12, 14}: 4, {12, 15}: 4, {12, 16}: 4, {12, 17}: 4, {12, 18}: 4, {12, 19}: 4,
{13, 10}: 4, {13, 11}: 4, {13, 12}: 4, {13, 13}: 4, {13, 14}: 4, {13, 15}: 4, {13, 16}: 4, {13, 17}: 4, {13, 18}: 4, {13, 19}: 4,
{14, 10}: 4, {14, 11}: 4, {14, 12}: 4, {14, 13}: 4, {14, 14}: 4, {14, 15}: 4, {14, 16}: 4, {14, 17}: 4, {14, 18}: 4, {14, 19}: 4,
{15, 10}: 4, {15, 11}: 4, {15, 12}: 4, {15, 13}: 4, {15, 14}: 4, {15, 15}: 4, {15, 16}: 4, {15, 17}: 4, {15, 18}: 4, {15, 19}: 4,
{16, 10}: 4, {16, 11}: 4, {16, 12}: 4, {16, 13}: 4, {16, 14}: 4, {16, 15}: 4, {16, 16}: 4, {16, 17}: 4, {16, 18}: 4, {16, 19}: 4,
{17, 10}: 4, {17, 11}: 4, {17, 12}: 4, {17, 13}: 4, {17, 14}: 4, {17, 15}: 4, {17, 16}: 4, {17, 17}: 4, {17, 18}: 4, {17, 19}: 4,
{18, 10}: 4, {18, 11}: 4, {18, 12}: 4, {18, 13}: 4, {18, 14}: 4, {18, 15}: 4, {18, 16}: 4, {18, 17}: 4, {18, 18}: 4, {18, 19}: 4,
{19, 10}: 4, {19, 11}: 4, {19, 12}: 4, {19, 13}: 4, {19, 14}: 4, {19, 15}: 4, {19, 16}: 4, {19, 17}: 4, {19, 18}: 4, {19, 19}: 4,
}
var panneauxCarte map[ZoneID][]alg.Node = map[ZoneID][]alg.Node{
// Placement des panneaux d'orientation
// Besoin des coordonnées et de l'heuristique de départ (pour choisir vers quel panneau aller (exemple, la distance jusqu'à la dest))
1: {*alg.NewNode(7, 11, 0, 1, 0, 0), *alg.NewNode(14, 11, 0, 10, 0, 0), *alg.NewNode(9, 5, 0, 7, 0, 0), *alg.NewNode(14, 15, 0, 15, 0, 0)},
2: {*alg.NewNode(14, 11, 0, 5, 0, 0), *alg.NewNode(10, 19, 0, 1, 0, 0), *alg.NewNode(14, 15, 0, 7, 0, 0)},
3: {*alg.NewNode(7, 11, 0, 10, 0, 0), *alg.NewNode(10, 19, 0, 5, 0, 0), *alg.NewNode(4, 11, 0, 15, 0, 0)},
4: {*alg.NewNode(7, 11, 0, 10, 0, 0), *alg.NewNode(10, 19, 0, 5, 0, 0)},
}
var playground [20][20]string = [20][20]string{
{"_", "X", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_", "_"},
......@@ -141,7 +87,7 @@ func NewSimulation(agentCount int, maxStep int, maxDuration time.Duration) (simu
// Communication entre agents
mapChan := make(map[AgentID]chan AgentID)
simu.env = *NewEnvironment([]Agent{}, carte, mapChan)
//simu.env = *NewEnvironment([]Agent{}, playground, mapChan,zonesCarte, panneauxCarte)
//simu.env = *NewEnvironment([]Agent{}, playground, mapChan)
// création des agents et des channels
for i := 0; i < agentCount; i++ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment