/// <summary> /// Initialise the model from the Quant2ModelProperties data and run it. /// </summary> /// <param name="ConnectionId"></param> /// <param name="q3mp"></param> public FMatrix[] LoadAndRun(QUANT3ModelProperties q3mp, FolderBrowserDialog f, ProgressBar pb, int exps) { nexp = exps; switch (this.modelType) { case 3: NumModes = 2; break; default: NumModes = 3; break; } for (int k = 0; k < NumModes; k++) { dis[k] = FMatrix.DirtyDeserialise(f.SelectedPath + "\\" + q3mp.Indis[k]); TObs[k] = FMatrix.DirtyDeserialise(f.SelectedPath + "\\" + q3mp.InTObs[k]); TObsCopy[k] = FMatrix.DirtyDeserialise(f.SelectedPath + "\\" + q3mp.InTObs[k]); } ////IsUsingConstraints = q3mp.IsUsingConstraints; if (IsUsingConstraints) { //set up the constraints input data from the green belt and land use data table Constraints = new float[TObs[0].N]; //load constraints file here - convert data table to array based on zonei code DataTable dt = (DataTable)Serialiser.Get(q3mp.InConstraints); int ConstraintCount = 0; foreach (DataRow row in dt.Rows) //this does assume that there is a zonei value for every slot in Constraints[] { int ZoneI = (int)row["zonei"]; float Gj = (float)row["Gj"]; Constraints[ZoneI] = Gj; if (Gj >= 1.0) { ++ConstraintCount; } } System.Diagnostics.Debug.WriteLine("ConstraintCount=" + ConstraintCount); } // InstrumentStatusText = "Starting model run"; pb.PerformStep(); Run(pb, f.SelectedPath); pb.PerformStep(); //constraints B weights if we're doing that if (IsUsingConstraints) { Serialiser.Put(q3mp.OutConstraintsB, B); } System.Diagnostics.Debug.WriteLine("DONE"); pb.Refresh(); return(TPred); }
private void button1_Click(object sender, EventArgs e) { using (var fbd = new FolderBrowserDialog()) { fbd.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); //fbd.SelectedPath = @"D:\desktopQuant\data\"; fbd.SelectedPath = @"D:\2020\grantBikes\data\tranus\"; DialogResult result = fbd.ShowDialog(); if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) { string[] files = Directory.GetFiles(fbd.SelectedPath); /*System.Windows.Forms.MessageBox.Show("Directory: " + fbd.SelectedPath.ToString(), "Message"); * System.Windows.Forms.MessageBox.Show("Files found: " + files.Length.ToString(), "Message"); * for (int i=0;i< files.Length;i++) * System.Windows.Forms.MessageBox.Show("Files found: " + files.ElementAt(i), "Message");*/ // Display the ProgressBar control. pBar1.Visible = true; pBar1.Minimum = 1; pBar1.Maximum = 100; pBar1.Value = 1; pBar1.Step = 10; FMatrix[] temp = new FMatrix[3]; //Data input to model. FMatrix[] mtotal = null; FMatrix[] mtemp = null; mtotal = new FMatrix[3]; mtemp = new FMatrix[3]; string[] OutTPred = { "TPred1.csv", "TPred2.csv", "TPred3.csv" }; string OutTPredCombined = "TPred.csv"; int N = 194; if (modelType == 3) { string dijprivate = "privateTimeCode.csv"; string dijprivateS = "dis_roads_min.bin"; string dijpublic = "publicTimeCode.csv"; string dijpublicS = "dis_bus_min.bin"; string tprivate = "viajesODprivadosM.csv"; string tpublicS = "TObs_1.bin"; string tpublic = "viajesODpublicosM.csv"; string tprivateS = "TObs_2.bin"; FMatrix dijPrivate = FMatrix.GenerateTripsLondon(fbd.SelectedPath + "\\" + dijprivate, N); dijPrivate.DirtySerialise(fbd.SelectedPath + "\\" + dijprivateS); FMatrix dijPublic = FMatrix.GenerateTripsLondon(fbd.SelectedPath + "\\" + dijpublic, N); dijPublic.DirtySerialise(fbd.SelectedPath + "\\" + dijpublicS); FMatrix tprivateM = FMatrix.GenerateTripsLondon(fbd.SelectedPath + "\\" + tprivate, N); tprivateM.DirtySerialise(fbd.SelectedPath + "\\" + tpublicS); FMatrix tpublicM = FMatrix.GenerateTripsLondon(fbd.SelectedPath + "\\" + tpublic, N); tpublicM.DirtySerialise(fbd.SelectedPath + "\\" + tprivateS); } int NumModes = 1; switch (this.modelType) { case 3: NumModes = 2; break; default: NumModes = 3; break; } QUANT3ModelProperties q = new QUANT3ModelProperties(); FMatrix[] TObs = new FMatrix[NumModes]; //Data input to model. for (int k = 0; k < NumModes; k++) { TObs[k] = FMatrix.DirtyDeserialise(fbd.SelectedPath + "\\" + q.InTObs[k]); } for (int k = 0; k < NumModes; k++) { mtotal[k] = new FMatrix(N, N); } for (int i = 0; i < nexperiments; i++) { QUANT3Model quant = new QUANT3Model(modelType); temp = quant.LoadAndRun(q, fbd, pBar1, i); //quant.LoadAndRun(q, fbd, pBar1); //mtemp = temp; for (int j = 0; j < NumModes; j++) { //mtemp[j] = temp[j]; //mtemp[j].DirtySerialise(fbd.SelectedPath + "\\" + OutTPred[j] + "_1"); temp[j].WriteCSVMatrix(fbd.SelectedPath + "\\" + OutTPred[j] + "_" + i.ToString() + ".csv"); } FMatrix TPredCombinedtmp = new FMatrix(N, N); float Sum = 0; for (int w = 0; w < TPredCombinedtmp.M; w++) { for (int j = 0; j < TPredCombinedtmp.N; j++) { for (int k = 0; k < NumModes; k++) { Sum += temp[k]._M[w, j]; } TPredCombinedtmp._M[w, j] = Sum; Sum = 0.0f; } } TPredCombinedtmp.WriteCSVMatrix(fbd.SelectedPath + "\\TPred_" + i.ToString() + ".csv"); for (int j = 0; j < NumModes; j++) { mtotal[j] = mtotal[j].SumMatrix(temp[j], N); } System.Diagnostics.Debug.WriteLine("run = " + i); } for (int j = 0; j < NumModes; j++) { mtotal[j] = mtotal[j].Scale(1.0f / nexperiments); } for (int k = 0; k < NumModes; k++) { //mtotal[k].DirtySerialise(fbd.SelectedPath + "\\" + OutTPred[k]); mtotal[k].WriteCSVMatrix(fbd.SelectedPath + "\\" + OutTPred[k]); } FMatrix TPredCombined = new FMatrix(N, N); for (int i = 0; i < TPredCombined.M; i++) { for (int j = 0; j < TPredCombined.N; j++) { float Sum = 0; for (int k = 0; k < NumModes; k++) { Sum += mtotal[k]._M[i, j]; } TPredCombined._M[i, j] = Sum; } } //TPredCombined.DirtySerialise(fbd.SelectedPath + "\\" + OutTPredCombined); TPredCombined.WriteCSVMatrix(fbd.SelectedPath + "\\" + OutTPredCombined); } button2.Enabled = true; } /*int size = -1; * DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. * if (result == DialogResult.OK) // Test result. * { * string file = openFileDialog1.FileName; * try * { * string text = File.ReadAllText(file); * size = text.Length; * } * catch (IOException) * { * } * } * Console.WriteLine(size); // <-- Shows file size in debugging mode. * Console.WriteLine(result); // <-- For debugging use.*/ }
/// <summary> /// Initialise the model from the Quant2ModelProperties data and run it. /// </summary> /// <param name="ConnectionId"></param> /// <param name="q3mp"></param> public void LoadAndRun(QUANT3ModelProperties q3mp, FolderBrowserDialog f, ProgressBar pb) { // HubConnectionId = ConnectionId; //deserialise the distance and TObs matrices // InstrumentStatusText = "Loading matrices"; /*string[] files = Directory.GetFiles(f.SelectedPath); * System.Windows.Forms.MessageBox.Show("Files found: " + files.Length.ToString(), "Message");*/ /*for (int i=0;i< files.Length;i++) * System.Windows.Forms.MessageBox.Show("Files found: " + files.ElementAt(i), "Message");*/ for (int k = 0; k < NumModes; k++) { dis[k] = FMatrix.DirtyDeserialise(f.SelectedPath + "\\" + q3mp.Indis[k]); TObs[k] = FMatrix.DirtyDeserialise(f.SelectedPath + "\\" + q3mp.InTObs[k]); } ////IsUsingConstraints = q3mp.IsUsingConstraints; if (IsUsingConstraints) { //set up the constraints input data from the green belt and land use data table Constraints = new float[TObs[0].N]; //load constraints file here - convert data table to array based on zonei code DataTable dt = (DataTable)Serialiser.Get(q3mp.InConstraints); int ConstraintCount = 0; foreach (DataRow row in dt.Rows) //this does assume that there is a zonei value for every slot in Constraints[] { int ZoneI = (int)row["zonei"]; float Gj = (float)row["Gj"]; Constraints[ZoneI] = Gj; if (Gj >= 1.0) { ++ConstraintCount; } } System.Diagnostics.Debug.WriteLine("ConstraintCount=" + ConstraintCount); } // InstrumentStatusText = "Starting model run"; pb.PerformStep(); Run(pb); pb.PerformStep(); //write out 3 modes of predicted matrix for (int k = 0; k < NumModes; k++) { TPred[k].DirtySerialise(f.SelectedPath + "\\" + q3mp.OutTPred[k]); } //and a combined mode so the visualisation can see the data //TODO: this block needs to change once the GUI is able to visualise the different modes separately FMatrix TPredCombined = new FMatrix(TPred[0].M, TPred[0].N); for (int i = 0; i < TPredCombined.M; i++) { for (int j = 0; j < TPredCombined.N; j++) { float Sum = 0; for (int k = 0; k < NumModes; k++) { Sum += TPred[k]._M[i, j]; } TPredCombined._M[i, j] = Sum; } } TPredCombined.DirtySerialise(f.SelectedPath + "\\" + q3mp.OutTPredCombined); //end combination block //constraints B weights if we're doing that if (IsUsingConstraints) { Serialiser.Put(q3mp.OutConstraintsB, B); } System.Diagnostics.Debug.WriteLine("DONE"); /*InstrumentStatusText = "Computing model statistics"; * StatisticsDataQ3 sd = new StatisticsDataQ3(); * DataTable PopulationTable = (DataTable)Serialiser.Get(q3mp.InPopulationFilename); * sd.ComputeFromModel(this, ref PopulationTable); * sd.SerialiseToXML(q3mp.InOutStatisticsFilename); * InstrumentStatusText = "Finished"; * InstrumentFinished();*/ }