// Use this for initialization void Start() { robots = findtag("robot"); numrobot = robots.Length; Area[] aree = ConvexOverlapping.divideSpaceIntoArea(); positions = new Vector3[aree.Length]; numaree = aree.Length; for (int i = 0; i < aree.Length; i++) { positions[i] = aree[i].center3D; } ff = new FitnessFunction(numrobot, robots, positions); ga = new GeneticAlgorithm(numrobot + aree.Length, 10, maxIteration, ff); /* * int[] solution = ga.run (); * * string log = "GA: ["; * for (int i=0; i<solution.Length; i++) { * log += solution[i] + ", "; * } * log = "]"; * Debug.Log (log); */ ga.first_generation(ga._population); }
void testFitness() { robots = findtag("robot"); numrobot = robots.Length; Area[] aree = ConvexOverlapping.divideSpaceIntoArea(); positions = new Vector3[aree.Length]; for (int i = 0; i < aree.Length; i++) { positions[i] = aree[i].center3D; } //Debug.Log (positions.Length); FitnessFunction ff = new FitnessFunction(numrobot, robots, positions); GeneticAlgorithm ga = new GeneticAlgorithm(numrobot + aree.Length, 10, 1000, ff); int[] individual = new int[] { 0, 1, 2, 3, 4, 5, 6 }; Debug.Log("Fitness: " + ga.calculateFitness(individual)); individual = new int[] { 0, 1, 2, 3, 6, 4, 5 }; Debug.Log("Fitness: " + ga.calculateFitness(individual)); individual = new int[] { 0, 2, 3, 6, 1, 4, 5 }; Debug.Log("Fitness: " + ga.calculateFitness(individual)); makeItMove(individual); }
// Use this for initialization void Start() { Area[] aree = ConvexOverlapping.divideSpaceIntoArea(); graph = new Graph(aree); graph.drawConnections(); graph.printNodes(); }
// Use this for initialization void Start() { Area[] aree = ConvexOverlapping.divideSpaceIntoArea(); graph = new Graph(aree); //graph.drawConnections (); graph.printNodes(); //Debug.Log (); robots = findtag("robot"); int R = robots.Length; int[] r = new int[R]; for (int i = 0; i < R; i++) { r[i] = graph.findInGraph(robots [i]); //Debug.Log ("robot "+r[i]); } pe = new PEalgorithmV2(graph, r); //Path path = pe.PEstep (maxIteration); //path.print (); pe.inizializzation(); }
private void distTest() { Area[] aree = ConvexOverlapping.divideSpaceIntoArea(); graph = new Graph(aree); // Debug.Log ("Shortest path dist nodes 3 to 0: "+graph.dist (3, 0)); // Debug.Log ("Shortest path dist nodes 3 to 1: "+graph.dist (3, 1)); // Debug.Log ("Shortest path dist nodes 3 to 2: "+graph.dist (3, 2)); int[] robots = new int[] { 0, 0 }; int[] dirtySet = new int[] { 1, 0, 0, 1 }; Debug.Log("Distance test: robot [0, 0]: " + dist(robots, dirtySet)); }
// Use this for initialization void Start() { aree = ConvexOverlapping.divideSpaceIntoArea(); graph = new Graph(aree); //secondo me aree dovrà essere statico utilizzabile da tutti gli algoritmi // graph.constructgraph (); Node[] nodes = cooperativesearch_paths(graph); for (int i = 0; i < nodes.Length; i++) { Debug.Log(nodes[i].area.center3D); } robots = findtag("robot"); numrobot = robots.Length; Debug.Log("robots: " + numrobot); positions = new Vector3[nodes.Length]; numaree = nodes.Length; for (int i = 0; i < numaree; i++) { positions[i] = nodes[i].area.center3D; } Debug.Log("num robot: " + numrobot); Debug.Log("num aree: " + numaree); ff = new FitnessFunction(numrobot, robots, positions); ga = new GeneticAlgorithm(numrobot + numaree, 10, maxIteration, ff); ga.first_generation(ga._population); /* * graph.printNodes (); * Node n = graph.nodes [1]; * ArrayList list = n.connection; * foreach (Node nod in list) {//è pseudo codice perchè non ho capito come prendere il nodo dall'arraylist * Debug.Log (nod.area.center3D); * } * * graph.removenode (graph.nodes[1]); * graph.printNodes (); * * list = n.connection; * foreach (Node nod in list) {//è pseudo codice perchè non ho capito come prendere il nodo dall'arraylist * Debug.Log (nod.area.center3D); * } */ }
//private Vector3[] robots; // Use this for initialization void Start() { Area[] aree = ConvexOverlapping.divideSpaceIntoArea(); Graph graph = new Graph(aree); Vector3[] robots = findtag("robot"); //findtag("robot"); Node[] nodes = cooperativesearch_paths(graph); Debug.Log("Num areas: " + nodes.Length); for (int i = 0; i < robots.Length && i < nodes.Length; i++) { createPoint(nodes[i].area.center3D); ArrayList path = new ArrayList(); path.Add(nodes[i].area.center3D); robotsObject [i].path = path; } for (int i = 0; i < robots.Length && i < nodes.Length; i++) { robotsObject [i].go = true; } }
// Use this for initialization void Start() { robots = findtag("robot"); //positions = findtag("area"); Area[] aree = ConvexOverlapping.divideSpaceIntoArea(); positions = new Vector3[aree.Length]; for (int i = 0; i < aree.Length; i++) { positions[i] = aree[i].center3D; } vrpstart = fill(robots, positions); numrobot = robots.Length; numpos = positions.Length; everyone = new Vector3[numpos + numrobot]; int j = 0; for (int i = 0; i < numrobot; i++) { everyone[j] = robots[i]; j++; } for (int i = 0; i < numpos; i++) { everyone[j] = positions[i]; j++; } int[] vrp_actual = Shuffleint(vrpstart); int[] vrp_bestfit = new int[vrp_actual.Length]; for (int i = 0; i < vrp_actual.Length; i++) { vrp_bestfit[i] = vrp_actual[i]; } int actualfit = fit(vrp_actual); int bestfit = actualfit; for (int i = 0; i < iteration; i++) { vrp_actual = Shuffleint(vrp_actual); actualfit = fit(vrp_actual); if (actualfit < bestfit) { bestfit = actualfit; //vrp_bestfit = vrp_actual; for (int z = 0; z < vrp_actual.Length; z++) { vrp_bestfit[z] = vrp_actual[z]; } } } //now maybe we have to draw the lines, or simply make them move in update vrp_bestfit = rotateToRobot(vrp_bestfit); string log = ""; for (int i = 0; i < vrp_bestfit.Length; i++) { log += vrp_bestfit[i] + " "; createPoint((Vector3)everyone[vrp_bestfit[i]]); } Debug.Log(log); int actual_robot = -1; ArrayList path = new ArrayList(); for (int i = 0; i < (numpos + numrobot); i++) { if (vrp_bestfit[i] < numrobot) { //if it is a robot if (actual_robot != -1) { robotsObject[actual_robot].path = path; } actual_robot = vrp_bestfit[i]; path = new ArrayList(); } else { //if it is a area path.Add(everyone[vrp_bestfit[i]]); } } if (actual_robot != -1) { robotsObject[actual_robot].path = path; } foreach (MoveRobotDifferential rob in robotsObject) { rob.go = true; } }