private void init_orders(read_file r) { orders = new List <int[]>(); for (int i = 1; i <= r.total_train_num; i++) { if (r.dir[i - 1] == 1) { for (int j = 0; j < r.station_num - 1; j++) { int[] now_order = new int[2] { i, j + 1 }; orders.Add(now_order); } } else { for (int j = 0; j < r.station_num - 1; j++) { int[] now_order = new int[2] { i, r.station_num - j - 1 }; orders.Add(now_order); } } } }
private void 读取ToolStripMenuItem_Click(object sender, EventArgs e) { FolderBrowserDialog fb = new FolderBrowserDialog(); fb.Description = "请选择输入文件所在文件夹"; string input_path; if (fb.ShowDialog() == DialogResult.OK) { input_path = fb.SelectedPath; } else { return; } r = new read_file(input_path); for (int i = 0; i < r.total_train_num; i++) { comboBox1.Items.Add(i + 1); comboBox2.Items.Add(i + 1); } comboBox1.SelectedIndex = 0; for (int i = 0; i < r.station_num; i++) { comboBox3.Items.Add(i + 1); } comboBox1.SelectedIndex = 0; comboBox2.SelectedIndex = 0; comboBox3.SelectedIndex = 0; }
public mat(read_file r, int train_num) { this.train_num = train_num; this.r = r; int flag = r.dir[train_num - 1]; station_range = new int[r.station_num]; if (flag == 1) { for (int i = 1; i <= r.station_num; i++) { station_range[i - 1] = i; } } else { for (int i = 1; i <= r.station_num; i++) { station_range[i - 1] = r.station_num - i + 1; } } time_len = time_sub2min(r.end_time, r.start_time) + 1; node_num = ((r.station_num - 2) * 3 + 2) * time_len + 2;//1 start_point 2 end_point s_t_mat = new int[node_num, node_num]; for (int i = 0; i < node_num; i++) { for (int j = 0; j < node_num; j++) { if (i == j) { continue; } else { s_t_mat[i, j] = int.MaxValue; } } } }
private Color building_colour = Color.white; //hold the final colour of the object void Start() { //create the object to hold the CSV file csvfile = gameObject.GetComponent <read_file>(); // Create a hashstring to hold the unique values of Avenue HashSet <string> csv_avenues = new HashSet <string>(); //find out the number of rows in the csv file csv_num_rows = csvfile.NumRows(); //loop through all rows to get a distinct list of the avenues //Note - A hashSet only allows distinct values to be added for (int i = 0; i < csv_num_rows; i++) { csv_avenues.Add(csvfile.GetAt(i).Avenue); } csv_num_avenue = (csv_avenues.Count); //Get the total number of Avenues by counting the unique elements in the hashset // Convert the avenues from the hash to a list so they can be indexed and retrieved List <string> avenues_list = csv_avenues.ToList(); //loop through the number of buildings for (int y = 0; y < csv_num_avenue; y++) { //as the loop steps through each avenue it uses the index to get the avenues associated rows and puts them in a list rows_on_avenue_list = csvfile.FindAll_Avenue(avenues_list[y]); //counts the total number or rows (or buildings for the avenue) to determine how long each avenue will be csv_num_rows = rows_on_avenue_list.Count(); //loop through the number of avenues for (int x = 0; x < csv_num_rows; x++) { // read the shape, colour and height for each row shape_building = rows_on_avenue_list[x].Building; //Building = Shape shape_colour = rows_on_avenue_list[x].Tenant; //Tenant = Colour shape_height = float.Parse(rows_on_avenue_list[x].Floors); //Floors = Height - need to convert string to int // ----------------- Select the right shape ----------------- // assign the correct prefabrication depending on the rows shape. // not all shapes have the middle set to ground level if (shape_building == "Square") { shape = brick; ground_adjust = 2.0f; //value needed for bricks } else if (shape_building == "Pyramid") { shape = pyramid; ground_adjust = 2.0f; //value needed for pyramids } else if (shape_building == "Pill") { shape = pill; ground_adjust = 1.0f; //value needed for pill } else if (shape_building == "Cylinder") { shape = cylinder; ground_adjust = 1.0f; //value needed for cylinder } else // if error then use sphere { shape = sphere; } // ----------------- Select the right colour ----------------- // assign the correct prefabrication depending on the rows shape. if (shape_colour == "Red") { building_colour = Color.red; } else if (shape_colour == "Green") { building_colour = Color.green; } else if (shape_colour == "Blue") { building_colour = Color.blue; } else if (shape_colour == "Yellow") { building_colour = Color.yellow; } else //if error use black { building_colour = Color.black; } //Create the vector location using the x and y coords - Set the Z based on the height of the object Vector3 pos = new Vector3(y * spacing, ((shape_height * z_scale) / ground_adjust), x * spacing); // the position of the y and x determine which way the array faces after it is built // divide by 2 on the height to make sure the bases are level // only use spacing on the X & Y coordinates not z otherwise it gets the height wrong // use that shape variable to build the object // this is the section of code that create the actual object and places it in space // uses the vector that was defined above to place it in the correct location in space GameObject shape_go = Instantiate(shape, pos, Quaternion.identity) as GameObject; // set the colour of the object shape_go.GetComponent <MeshRenderer>().material.color = building_colour; // set the hight of the object shape_go.transform.localScale = new Vector3(x_scale, shape_height * z_scale, y_scale); // Change the size of the shape using the height from the file and the other 3 dimensions to scale the shape } } }