// Reads all WCSPP instances from .txt files. // The instances are stored as tspinstances structs in an array called "tspinstances" private static GameManager.WCSPPInstance[] LoadWCSPPInstances(int numberOfInstances) { GameManager.WCSPPInstance[] wcsppInstances = new GameManager.WCSPPInstance[numberOfInstances]; for (int k = 0; k < numberOfInstances; k++) { // create a dictionary where all the variables and definitions are strings var dict = new Dictionary <string, string>(); // Use streamreader to read the input files if there are lines to read using (StreamReader sr = new StreamReader(folderPathLoadInstances + "w" + (k + 1) + ".txt")) { ReadToDict(sr, dict); } // Convert (most of them) to integers, with variables and literals being arrays and the others single literals wcsppInstances[k].coordinatesx = Array.ConvertAll(dict["coordinatesx"].Substring(1, dict["coordinatesx"].Length - 2).Split(','), float.Parse); wcsppInstances[k].coordinatesy = Array.ConvertAll(dict["coordinatesy"].Substring(1, dict["coordinatesy"].Length - 2).Split(','), float.Parse); wcsppInstances[k].distancematrix = StringToMatrix(dict["distancevector"]); wcsppInstances[k].weightmatrix = StringToMatrix(dict["weightvector"]); wcsppInstances[k].ncities = int.Parse(dict["ncities"]); wcsppInstances[k].maxweight = int.Parse(dict["maxweight"]); wcsppInstances[k].startcity = int.Parse(dict["startcity"]) - 1; wcsppInstances[k].endcity = int.Parse(dict["endcity"]) - 1; wcsppInstances[k].solution = int.Parse(dict["solution"]); } return(wcsppInstances); }
// Funciton to set up WCSPP instance void SetWCSPP(GameManager.WCSPPInstance currentInstance) { // Display Max distance Text quest = GameObject.Find("Question").GetComponent <Text>(); quest.text = "Max cost: $" + GameManager.wcsppInstances[currInstance].maxweight; // Display current distance DistanceText = GameObject.Find("DistanceText").GetComponent <Text>(); DistanceText.color = Color.yellow; // Display current weight WeightText = GameObject.Find("WeightText").GetComponent <Text>(); WeightText.color = Color.cyan; // Coordinate of the cities cox = currentInstance.coordinatesx; coy = currentInstance.coordinatesy; unitycoord = BoardFunctions.CoordinateConvertor(cox, coy); // Number of objects ncities = currentInstance.ncities; distances = currentInstance.distancematrix; weights = currentInstance.weightmatrix; solution = currentInstance.solution; // Store objects in a list items = new Item[ncities]; for (int i = 0; i < ncities; i++) { for (int j = i; j < ncities; j++) { if (distances[i, j] != 0) { DrawSlimLine(i, j, 0.01f); } } } for (int i = 0; i < ncities; i++) { items[i] = GenerateItem(i, unitycoord[i]); } }