Example #1
0
        /// <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);
        }
Example #2
0
        /// <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();*/
        }