void onClickSave() { GameObject car = null; // check if the simulation is running.... if (isRiding) { if (isSimulating) { String data = ""; //check the simulation tyep if (SimulationMode == 1) { car = Euclidean.FinalSelectedCar; data = Euclidean.getSavingData(); } if (SimulationMode == 2) { car = AntColonyController.FirstCar; data = AntColonyController.getSavingData(); } if (SimulationMode == 3) { data = MPAC.getSavingData(); } // save the data on a local file StreamWriter writer = new StreamWriter("Data.csv", true); writer.WriteLine(data); writer.Close(); } } }
void Refresh() { killAnts(); clearSelectedCarList(); carGenerator.RefreshCarColor(); algoAntColony.KillAntColonies(); btnAntColony.interactable = true; btnEuclidean.interactable = true; btnMPAC.interactable = true; transform.GetComponent <UserSelector>().resetNode(); DestroyPheremones(); MPAC.clearMapPheremones(); isSimulating = false; SimulationMode = 0; }
// 0 = no Simulation // 1 = Euclidean // 2 = Ant Colony // 3 = MPAC //GameObject EuclideanCar = null; //GameObject AntCar = null; //GameObject MPACCar = null; // Use this for initialization void Start() { nodeCount = nodeGrid * nodeGrid; algoEuclidean = gameObject.GetComponent <Euclidean> (); algoAntColony = gameObject.GetComponent <AntColonyController> (); algoMPAC = gameObject.GetComponent <MPAC> (); userSelector = gameObject.GetComponent <UserSelector> (); carGenerator = gameObject.GetComponent <CarGenerator> (); // create the under laying surface GameObject surface; surface = GameObject.CreatePrimitive(PrimitiveType.Quad); surface.transform.Rotate(new Vector3(90, 0, 0)); surface.transform.localScale = new Vector3(2 * boundry, 2 * boundry, 1); surface.GetComponent <MeshRenderer> ().material = groundMat; GenerateGraph(); isMapGenerated = true; resetButton.onClick.AddListener(onClickReset); btnEuclidean.onClick.AddListener(onClickEuclidean); btnAntColony.onClick.AddListener(onClickAntColony); btnMPAC.onClick.AddListener(onClickMPAC); sliderAntSpeed.onValueChanged.AddListener(onSliderValueChange); sliderPheremoneEvaporate.onValueChanged.AddListener(onPheremoneSliderValueChange); btnRefresh.onClick.AddListener(onRefreshButton); toggleHideAnts.onValueChanged.AddListener((value) => { onToggleHideAnts(); }); toggleGenderPref.onValueChanged.AddListener((value) => { onToggleGenderPref(value); }); toggleAgePref.onValueChanged.AddListener((value) => { onToggleAgePref(value); }); Gender_Male.onValueChanged.AddListener((value) => { onToggleGenderMale(value); }); Gender_Female.onValueChanged.AddListener((value) => { onToggleGenderFemale(value); }); Age_30.onValueChanged.AddListener((value) => { onToggleAge30(value); firstAgeCall = true; }); Age_49.onValueChanged.AddListener((value) => { onToggleAge49(value); firstAgeCall = true; }); Age_50.onValueChanged.AddListener((value) => { onToggleAge50(value); firstAgeCall = true; }); SaveButton.onClick.AddListener(onClickSave); carGenerator.Generate(carCount); }
void setTargetNode(Vector3 previousLocation) { if (!hasVisitedCar) { if (currentNode.ways.Count != 0) { // have to randomize them later. Vector3 targetPosition = currentNode.ways [UnityEngine.Random.Range(0, currentNode.ways.Count)]; // if there are multiple path connect give less weightage to where car came from.. if (currentNode.ways.Count > 1) { List <float> pheremoneList = new List <float> (); foreach (Vector3 way in currentNode.ways) { float pathPheremoneSum = 0; foreach (GameObject car in CarGenerator.carList) { float thisPathPheremone = transform.parent.GetComponent <MPAC> ().getPheremoneValue(currentNode.location, way, car); if (thisPathPheremone >= pathPheremoneSum) { pathPheremoneSum = thisPathPheremone; } } pheremoneList.Add(pathPheremoneSum); } float Sum = 0; foreach (float p in pheremoneList) { Sum = Sum + p; } if (Sum > 0) { List <float> weightageList = new List <float> (); weightageList = GetPheremoneWeightedList(pheremoneList, Sum); float spinWheel = UnityEngine.Random.Range(0, 100); int wayIndex = GetSelectedWayIndex(spinWheel, weightageList); targetPosition = currentNode.ways [wayIndex]; if (currentNode.location == UserSelector.selectedNode.transform.position) { spinWheel = UnityEngine.Random.Range(0, 100); wayIndex = GetSelectedWayIndex(spinWheel, weightageList); targetPosition = currentNode.ways [wayIndex]; } else { while (targetPosition == previousLocation) { spinWheel = UnityEngine.Random.Range(0, 100); wayIndex = GetSelectedWayIndex(spinWheel, weightageList); targetPosition = currentNode.ways [wayIndex]; } } ///// ***********************************************************// /// if there was no pheremone on any possible way simple choose any random node. } else { // never allow a U-turn for ant except for first node... while (targetPosition == previousLocation) { targetPosition = currentNode.ways [UnityEngine.Random.Range(0, currentNode.ways.Count)]; } } } List <Node> nodeList = MPAC.MPACColonyNodeList; targetNode = nodeList.Find(node => (node.location == targetPosition)); if (targetNode == null) { } } else { targetNode = currentNode; } } else { targetNode = pathTrace [pathTrace.Count - 1]; pathTrace.RemoveAt(pathTrace.Count - 1); } speedReductionFactor = MPAC.getRoadTraffic(targetNode.location, currentNode.location); }