Skip to content
Snippets Groups Projects
Commit a7f9ed36 authored by nollet's avatar nollet
Browse files

fin J5

parent a3b4c5dc
Branches
Tags
No related merge requests found
...@@ -55,7 +55,7 @@ Voici ici le descriptif du travail effectué lors de la journée du 17/05/2022. ...@@ -55,7 +55,7 @@ Voici ici le descriptif du travail effectué lors de la journée du 17/05/2022.
### de 16h à 18h ### de 16h à 18h
* fin changement architecture code projet * fin changement architecture code projet (voir src pour voir les différents dossiers et fichiers .cs)
<h2 id="mercredi"> <strong> 🧠 Journal de Bord - Jour 3</strong> <a href="#menu">↩️</a> </h2> <h2 id="mercredi"> <strong> 🧠 Journal de Bord - Jour 3</strong> <a href="#menu">↩️</a> </h2>
...@@ -64,15 +64,20 @@ Voici ici le descriptif du travail effectué lors de la journée du 18/05/2022. ...@@ -64,15 +64,20 @@ Voici ici le descriptif du travail effectué lors de la journée du 18/05/2022.
### De 8h30 à 10h ### De 8h30 à 10h
* Progression du code des Comportements et Perceptions
### de 10h à 12h ### de 10h à 12h
* Progression du code des Comportements et Perceptions
* Implémentation Comportement Composite
### de 14h à 16h ### de 14h à 16h
* Travail sur gestion des bords * Travail sur gestion des bords
### de 16h à 18h ### de 16h à 18h
* Gestion des bords OK * Gestion des bords OK, ajout de comportement adéquate
<h2 id="jeudi"> <strong> ☀️ Journal de Bord - Jour 4</strong> <a href="#menu">↩️</a> </h2> <h2 id="jeudi"> <strong> ☀️ Journal de Bord - Jour 4</strong> <a href="#menu">↩️</a> </h2>
...@@ -88,10 +93,13 @@ Voici ici le descriptif du travail effectué lors de la journée du 19/05/2022. ...@@ -88,10 +93,13 @@ Voici ici le descriptif du travail effectué lors de la journée du 19/05/2022.
### de 14h à 16h ### de 14h à 16h
* Réflexion sur concept : considération de la topologie comme un objet
* Ajout comportement restrictif 2D
### de 16h à 18h ### de 16h à 18h
* Possibilité de switcher entre environnement 2D et 3D
<h2 id="vendredi"> <strong> 🐦 Journal de Bord - Jour 5</strong> <a href="#menu">↩️</a> </h2> <h2 id="vendredi"> <strong> 🐦 Journal de Bord - Jour 5</strong> <a href="#menu">↩️</a> </h2>
Voici ici le descriptif du travail effectué lors de la journée du 20/05/2022. Voici ici le descriptif du travail effectué lors de la journée du 20/05/2022.
...@@ -100,6 +108,14 @@ Voici ici le descriptif du travail effectué lors de la journée du 20/05/2022. ...@@ -100,6 +108,14 @@ Voici ici le descriptif du travail effectué lors de la journée du 20/05/2022.
### de 10h à 12h ### de 10h à 12h
* Changement fonctionnement du comportement composite (insertion poids d'importance)
* Réflexion sur l'intersection de bords (2 stratégies possibles, à discuter)
### de 14h à 16h ### de 14h à 16h
* Lecture et compréhension partie implémentation des règles de nuées du papier scientifique
### de 16h à 18h ### de 16h à 18h
* Début implémentation comportement du papier
* Lecture de l'article scientifique donnée par l'encadrant.
\ No newline at end of file
...@@ -20,11 +20,15 @@ public class Agent : MonoBehaviour, Visible ...@@ -20,11 +20,15 @@ public class Agent : MonoBehaviour, Visible
void Start() void Start()
{ {
system = GameObject.Find("SMA").GetComponent<SMA>(); system = GameObject.Find("SMA").GetComponent<SMA>();
//comportement = new Reynolds(this);
List<Comportement> comps = new List<Comportement> { new Reynolds(this), new Bord(this)}; //List<Comportement> comps = new List<Comportement> { new Reynolds(this), new Bord(this), new Aleatoire(this)};
Comportement c = new CompositeSeq(this,comps); List<Comportement> comps = new List<Comportement> { new Paper(this), new Bord(this), new Aleatoire(this)};
List<int> imps = new List<int> { 5,8,1 };
Comportement c = new CompositeSeq(this,comps,imps);
if(system._3D) comportement = c; if(system._3D) comportement = c;
else comportement = new Constrain2D(this,c); else comportement = new Constrain2D(this,c);
perception = new Perception180(this,20.0f); perception = new Perception180(this,20.0f);
direction = Vector3.zero; direction = Vector3.zero;
speed = 0.7f; speed = 0.7f;
......
...@@ -15,13 +15,23 @@ public class Bord : Comportement ...@@ -15,13 +15,23 @@ public class Bord : Comportement
vectors.Add(proprietaire.direction); vectors.Add(proprietaire.direction);
foreach(Observation o in observation) { foreach(Observation o in observation) {
if (!o.objet.isAlive()) { if (!o.objet.isAlive()) {
if(grandDanger(o)) for(int i=0;i<8;i++) vectors.Add(fuir(o.distance)); if(grandDanger(o)) for(int i=0;i<8;i++) vectors.Add(fuir(o.distance));
else if(moyenDanger(o)) for(int i=0;i<5;i++) vectors.Add(fuir(o.distance)); else if(moyenDanger(o)) for(int i=0;i<5;i++) vectors.Add(fuir(o.distance));
else if(petitDanger(o)) for(int i=0;i<3;i++) vectors.Add(fuir(o.distance)); else if(petitDanger(o)) for(int i=0;i<3;i++) vectors.Add(fuir(o.distance));
/*
if(grandDanger(o)) for(int i=0;i<8;i++) vectors.Add(fuir(proprietaire.direction));
else if(moyenDanger(o)) for(int i=0;i<5;i++) vectors.Add(fuir(proprietaire.direction));
else if(petitDanger(o)) for(int i=0;i<3;i++) vectors.Add(fuir(proprietaire.direction));
*/
} }
} }
Vector3 res = Utils.meanVector(vectors); Vector3 res = Utils.meanVector(vectors);
return Utils.noiseVector(res,nbBruit,bruit); return res;
//return Utils.noiseVector(res,nbBruit,bruit);
} }
private bool grandDanger(Observation o) { private bool grandDanger(Observation o) {
......
...@@ -6,18 +6,21 @@ public class CompositeSeq : Comportement ...@@ -6,18 +6,21 @@ public class CompositeSeq : Comportement
{ {
protected List<Comportement> comportements; protected List<Comportement> comportements;
protected List<int> importances;
public CompositeSeq(Agent proprietaire,List<Comportement> c) : base(proprietaire) { public CompositeSeq(Agent proprietaire,List<Comportement> c,List<int> i) : base(proprietaire) {
comportements = c; comportements = c;
importances = i;
} }
public CompositeSeq(Agent proprietaire) : base(proprietaire) { public CompositeSeq(Agent proprietaire) : base(proprietaire) {
comportements = new List<Comportement>(); comportements = new List<Comportement>();
importances = new List<int>();
} }
public void removeComportement(int i) { comportements.RemoveAt(i); } public void removeComportement(int i) { comportements.RemoveAt(i);importances.RemoveAt(i); }
public void AddComportement(Comportement c) { comportements.Add(c); } public void AddComportement(Comportement c, int i) { comportements.Add(c); importances.Add(i);}
public override Vector3 reagir(List<Observation> observation) { public override Vector3 reagir(List<Observation> observation) {
List<Vector3> vectors = new List<Vector3>(); List<Vector3> vectors = new List<Vector3>();
...@@ -25,7 +28,7 @@ public class CompositeSeq : Comportement ...@@ -25,7 +28,7 @@ public class CompositeSeq : Comportement
Vector3 add; Vector3 add;
for(int i=0;i<comportements.Count;i++) { for(int i=0;i<comportements.Count;i++) {
add = comportements[i].reagir(observation); add = comportements[i].reagir(observation);
vectors.Add(add); for(int j=0; j<importances[i];j++) vectors.Add(add);
} }
return Utils.meanVector(vectors); return Utils.meanVector(vectors);
} }
......
...@@ -4,10 +4,45 @@ using UnityEngine; ...@@ -4,10 +4,45 @@ using UnityEngine;
public class Paper : Comportement public class Paper : Comportement
{ {
public Paper(Agent proprietaire) : base(proprietaire) {}
private static List<Vector3> moves = new List<Vector3>
{
(new Vector3(-1.0f,1.0f,0.0f)).normalized, (new Vector3(0.0f,1.0f,0.0f)).normalized, (new Vector3(1.0f,1.0f,0.0f)).normalized,
(new Vector3(-1.0f,0.0f,0.0f)).normalized, (new Vector3(0.0f,0.0f,0.0f)).normalized, (new Vector3(1.0f,0.0f,0.0f)).normalized,
(new Vector3(-1.0f,-1.0f,0.0f)).normalized, (new Vector3(0.0f,-1.0f,0.0f)).normalized, (new Vector3(1.0f,-1.0f,0.0f)).normalized
};
public Paper(Agent proprietaire) : base(proprietaire) {
}
public override Vector3 reagir(List<Observation> observation) { public override Vector3 reagir(List<Observation> observation) {
return Utils.randomDirection();
float disatifaction = 1.0f; Vector3 themove = Vector3.zero; float d;
for(int i=0;i<moves.Count;i++) {
d = computeDisatisfaction(moves[i],observation);
if (d < disatifaction) {
themove = moves[i]; disatifaction = d;
}
}
return themove;
}
private float computeDisatisfaction(Vector3 move, List<Observation> observation) {
float d = 0.0f; int nb = 0;
float m = proprietaire.system.environnement.getMaxDistance();
Vector3 possiblePos = proprietaire.transform.position + move;
for(int i=0;i<observation.Count;i++) {
if (observation[i].objet.isAlive()) {
d += Utils.abs(Utils.normVector(observation[i].distance) - idealDistance((Agent) observation[i].objet));
nb += 1;
}
}
return d/(nb*m);
}
private float idealDistance(Agent other) {
return 50.0f;
} }
} }
...@@ -22,7 +22,8 @@ public class Reynolds : Comportement ...@@ -22,7 +22,8 @@ public class Reynolds : Comportement
} }
} }
Vector3 res = Utils.meanVector(vectors); Vector3 res = Utils.meanVector(vectors);
return Utils.noiseVector(res,nbBruit,bruit); return res;
//return Utils.noiseVector(res,nbBruit,bruit);
} }
private bool danger(Observation o) { private bool danger(Observation o) {
......
...@@ -40,6 +40,10 @@ public class Environnement : MonoBehaviour ...@@ -40,6 +40,10 @@ public class Environnement : MonoBehaviour
return topologie.validPosition(); return topologie.validPosition();
} }
public float getMaxDistance() {
return topologie.getMaxDistance();
}
public void changeTo3D(bool _3D) { public void changeTo3D(bool _3D) {
foreach (Transform child in transform) Destroy(child.gameObject); foreach (Transform child in transform) Destroy(child.gameObject);
if(_3D) topologie = new Cube(cube); if(_3D) topologie = new Cube(cube);
......
...@@ -46,8 +46,23 @@ public class Cube : Topologie ...@@ -46,8 +46,23 @@ public class Cube : Topologie
return new Observation(new Obstacle(res),res-pos); return new Observation(new Obstacle(res),res-pos);
} }
protected List<List<Vector3>> getFaces() {
List<List<Vector3>> res = new List<List<Vector3>>();
res.Add(new List<Vector3> {new Vector3(minX,minY,minZ),new Vector3(minX,maxY,minZ), new Vector3(minX,maxY,maxZ), new Vector3(minX,minY,maxZ)});
res.Add(new List<Vector3> {new Vector3(maxX,minY,minZ),new Vector3(maxX,maxY,minZ), new Vector3(maxX,maxY,maxZ), new Vector3(maxX,minY,maxZ)});
res.Add(new List<Vector3> {new Vector3(minX,minY,minZ),new Vector3(maxX,minY,minZ), new Vector3(maxX,minY,maxZ), new Vector3(minX,minY,maxZ)});
res.Add(new List<Vector3> {new Vector3(minX,maxY,minZ),new Vector3(maxX,maxY,minZ), new Vector3(maxX,maxY,maxZ), new Vector3(minX,maxY,maxZ)});
res.Add(new List<Vector3> {new Vector3(minX,minY,minZ),new Vector3(maxX,minY,minZ), new Vector3(maxX,maxY,minZ), new Vector3(minX,maxY,minZ)});
res.Add(new List<Vector3> {new Vector3(minX,minY,maxZ),new Vector3(maxX,minY,maxZ), new Vector3(maxX,maxY,maxZ), new Vector3(minX,maxY,maxZ)});
return res;
}
public override Vector3 validPosition() { public override Vector3 validPosition() {
return Utils.randomVector(minX, maxX, minY, maxY, minZ, maxZ); return Utils.randomVector(minX, maxX, minY, maxY, minZ, maxZ);
} }
public override float getMaxDistance() {
return Utils.normVector(minX,maxX,minY,maxY,minZ,maxZ);
}
} }
...@@ -13,4 +13,6 @@ public abstract class Topologie ...@@ -13,4 +13,6 @@ public abstract class Topologie
public abstract Vector3 validPosition(); public abstract Vector3 validPosition();
public abstract float getMaxDistance();
} }
...@@ -59,6 +59,10 @@ public class Utils ...@@ -59,6 +59,10 @@ public class Utils
return (float) Math.Sqrt(Math.Pow(v.x,2) + Math.Pow(v.y,2) + Math.Pow(v.z,2)); return (float) Math.Sqrt(Math.Pow(v.x,2) + Math.Pow(v.y,2) + Math.Pow(v.z,2));
} }
public static float normVector(float minX, float maxX, float minY, float maxY, float minZ, float maxZ) {
return (float) Math.Sqrt(Math.Pow(maxX-minX,2) + Math.Pow(maxY-minY,2) + Math.Pow(maxZ-minZ,2));
}
public static Vector3 noiseVector(Vector3 v, int nbBruit, float bruit ) { public static Vector3 noiseVector(Vector3 v, int nbBruit, float bruit ) {
int coin1; int coin2; float x = v.x; float y = v.y; float z = v.z; int coin1; int coin2; float x = v.x; float y = v.y; float z = v.z;
for(int i=0;i<nbBruit;i++) { for(int i=0;i<nbBruit;i++) {
...@@ -80,4 +84,6 @@ public class Utils ...@@ -80,4 +84,6 @@ public class Utils
return normalizedVector(x,y,z); return normalizedVector(x,y,z);
} }
public static float abs(float n) {return (float) Math.Sqrt(Math.Pow(n,2));}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment