// Use this for initialization void Start() { numberAcceptedTrials = 0; logfiletimestamp = System.DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss_fff"); //Maximum possible cost. // TODO: don't hard code this and maybe choose a better starting temp STARTING_TEMP = temperature = 1f / Mathf.Pow(.95f, maxTrials / 2); CostStartingTemp = temperature; instance = this; trialWeights = new ArrayList(); prevTrialWeights = new ArrayList(); int totalNumberOfWeights = 0; int numberOfWeights; foreach (System.Type t in costsToUse) { numberOfWeights = (int)t.GetMethod("GetNumberWeights", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).Invoke(null, null); double[] defaultWeightCosts = (double[])t.GetMethod("GetDefaultWeightCosts", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).Invoke(null, null); for (int i = 0; i < numberOfWeights; i++) { this.trialWeights.Add(new Weight(defaultWeightCosts[i])); } totalNumberOfWeights += numberOfWeights; } Debug.Log("Number of weights testing: " + totalNumberOfWeights); Debug.Log(costsToUse.Length + " main weight(s) and " + (totalNumberOfWeights - costsToUse.Length) + " subweight(s)"); copyOverTrialWeightsToCache(); temperatures = new float[trialWeights.Count]; numGeneratedParameters = new int[trialWeights.Count]; ti_os = new float[trialWeights.Count]; for (int i = 0; i < temperatures.Length; i++) { ti_os[i] = STARTING_TEMP; } current_gradients = new float[trialWeights.Count]; max_gradients = new float[trialWeights.Count]; for (int i = 0; i < temperatures.Length; i++) { temperatures[i] = temperature; } bestWeights = new ArrayList(); calculate_c_i(); this.LaunchNextTrial(); }
public CostManager(KnowledgeBase knowledgeBase, SensorModule sm) { ArrayList desiredCosts = new ArrayList(); constraints = new ArrayList(); System.Object[] args = new System.Object[] { (System.Object)knowledgeBase, (System.Object)sm }; int weightIndex = 0; foreach (System.Type costType in WorldStateManager.GetListOfCostsToUse()) { // Debug.Log("Cost: " + costType.ToString()); if (costType.ToString() == "CollisionCost") { // Hack collisions are constraints not costs. Debug.Log("Adding collision constraint!!" + costType.ToString()); Cost collisionConstraint = new CollisionCost(knowledgeBase, sm); int numConstraintWeights = (int)CollisionCost.GetNumberWeights(); ArrayList localConstraintWeights = collisionConstraint.GetAllWeights(); for (int i = 0; i < numConstraintWeights; i++) { ((Weight)localConstraintWeights [i]).weightValue = TrialRunner.GetSingletonInstance().GetTrialWeightValueAt(weightIndex++); } collisionConstraint.GetAllWeights(); constraints.Add(collisionConstraint); } else { Cost c = (Cost)System.Activator.CreateInstance(costType, args); c.SetName(costType.ToString()); desiredCosts.Add(c); //Get the weights to test from the trial runner and set them // TODO: make this much better coded int numWeights = (int)costType.GetMethod("GetNumberWeights", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).Invoke(null, null); // Debug.Log(numWeights); ArrayList localWeights = c.GetAllWeights(); for (int i = 0; i < numWeights; i++) { ((Weight)localWeights [i]).weightValue = TrialRunner.GetSingletonInstance().GetTrialWeightValueAt(weightIndex++); } } } costs = desiredCosts; }
public static void EndTrial() { trialOngoing = false; TrialRunner.GetSingletonInstance().EndTrial(); Debug.Log("Trial Ending with time: " + timeElapsed); Debug.Log("Sustained " + numberOfCollisions + " collisions"); // If any agents exist destroy them foreach (Agent a in currentAgents) { Destroy(a.gameObject); } if (zone != null) { zone.DestroyTiles(); zone.CleanUp(); zone = null; } currentAgents.Clear(); foreach (Packet p in packetQueue) { p.CleanUp(); } packetQueue.Clear(); foreach (Packet p in packets) { p.CleanUp(); } packets.Clear(); //Callback to trial runner TrialRunner.GetSingletonInstance().LaunchNextTrial(); }