public override bool Execute()
        {
            Treatment.Result = ActiveResult;

            // Apply Treatment
            return(Treatment.ApplyOn());
        }
        public override bool Execute()
        {
            bool status = true;



            /*
             *
             * // Name of the results file
             * StudyExecutionDialog studyExecutionDialog = new StudyExecutionDialog();
             * System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(studyExecutionDialog);
             * //            studyExecutionDialog.Owner = this;
             * bool? result = studyExecutionDialog.ShowDialog(); // Show model dialog
             *
             * if (result == true)
             * {
             * Result currentResult = new Result(studyExecutionDialog.ResultName);
             * string fullPath = System.IO.Path.Combine("Studies", this.Name, studyExecutionDialog.ResultName + ".sdf");
             * currentResult.DatabasePath = fullPath;
             * this.Results.Add(currentResult);
             * this.ActiveResult = currentResult;
             * }
             * else
             * {
             * studyExecutionDialog.Close();
             * }
             *
             */



            Treatment.Result = ActiveResult;

            status = Treatment.ApplyOn();



            string CurrentDir = System.IO.Directory.GetCurrentDirectory();
            string FileName   = Name;

            if (File.Exists(CurrentDir + "\\" + FileName + ".acdstd"))
            {
                FileName = Name + "_" + DateTime.Today.Day + "-" + DateTime.Today.Month + "-" + DateTime.Today.Year + "_" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second;
            }


            /*
             * string output1 = File.ReadAllText("evaluatedSolutions.txt");
             * FileStream filer1 = new FileStream(CurrentDir + "\\" + FileName + ".acdstd", FileMode.Append, FileAccess.Write);
             * StreamWriter evals1 = new StreamWriter(filer1);
             * evals1.Write(output1);
             * evals1.Close();
             * filer1.Close();
             */


            return(status);
        }
        public override bool Execute()
        {
            bool status = true;

            if (Treatment is NSGAIIOptimiser || Treatment is SGAOptimizer)
            {
                throw new NotImplementedException("NSGAII or SGA  used a GUI to define some parameters, removing this dependencies needs to be implemented");

                //// GA setup
                //var gaSetup = new GASetup();
                //gaSetup.ShowDialog();
                //GAParameters gaParameters = gaSetup.GAParameters;
                //gaParameters.EvaluatedSolutionsFile = Path.Combine(AircadiaProject.ProjectPath, "evaluatedSolutions.txt");
                //((NSGAII)(Treatment)).GAParameters = gaParameters;
            }

            Treatment.Result = ActiveResult;

            status = Treatment.ApplyOn();

            return(status);
        }
        public override bool Execute()
        {
            bool status = Treatment.ApplyOn();

            return(status);
        }
        //public Treatment Treatment { get; }

        public override bool Execute()
        {
            bool status = true;



            /*
             #region Atif
             * string databaseFileName = Path.Combine(AircadiaProject.ProjectPath, "Studies\\" + this.Name + "\\" + this.Name + ".sdf"); // Microsoft SQL server compact edition file
             *
             * // Create database for optimisation results
             * string connectionString;
             *
             * connectionString = string.Format("Data Source = " + databaseFileName + ";Persist Security Info=False");
             * SqlCeEngine engine = new SqlCeEngine(connectionString);
             *
             * // Create tables
             * SqlCeConnection connection = new SqlCeConnection(connectionString);
             * if (connection.State == ConnectionState.Closed)
             * {
             *  connection.Open();
             * }
             *
             *
             *
             *
             *
             * // Create SQL statement command for "SQL Server Compact Edition"
             * SqlCeCommand command1 = new SqlCeCommand(sqlStatement1, connection);
             * SqlCeCommand command2 = new SqlCeCommand(sqlStatement2, connection);
             * // Execute the SQL command
             * try
             * {
             *  command1.ExecuteNonQuery();
             *  command2.ExecuteNonQuery();
             * }
             * catch (SqlCeException sqlexception)
             * {
             *  Console.WriteLine(sqlexception.Message);
             * }
             * catch (Exception ex)
             * {
             *  Console.WriteLine(ex.Message);
             * }
             #endregion Atif
             */



            if (Treatment is NSGAIIOptimiser opt)
            {
                //throw new NotImplementedException("NSGAII or SGA  used a GUI to define some parameters, removing this dependencies needs to be implemented");

                //opt.GAParameters.SelectionOprMethod = Treatments.Optimisers.GA.Selection.SelectionOprMethods.TournamentSelectionWithoutReplacement;
                //opt.GAParameters.CrossoverOprMethod = Treatments.Optimisers.GA.Crossover.CrossoverOprMethods.UniformCrossover;
                //opt.GAParameters.MutationOprMethod = Treatments.Optimisers.GA.Mutation.MutationOprMethods.PolynomialMutation;
                //opt.GAParameters.EvaluatedSolutionsFile = Path.Combine(AircadiaProject.ProjectPath, "evaluatedSolutions.txt");

                // UI Code
                //    NoOfGenerations = (int)numericUpDownNoOfGenerations.Value;
                //GAParameters.NoOfGenerations = NoOfGenerations;

                //PopulationSize = (int)numericUpDownPopulationSize.Value;
                //GAParameters.PopulationSize = PopulationSize;

                //if ((comboBoxSelectionOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Roulette Wheel")
                //    GAParameters.SelectionOprMethod = SelectionOprMethods.RouletteWheelSelection;
                //else if ((comboBoxSelectionOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Tournament Without Replacement")
                //    GAParameters.SelectionOprMethod = SelectionOprMethods.TournamentSelectionWithoutReplacement;
                //else if ((comboBoxSelectionOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Tournament With Replacement")
                //    GAParameters.SelectionOprMethod = SelectionOprMethods.TournamentSelectionWithReplacement;

                //if ((comboBoxCrossoverOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "One-Point")
                //    GAParameters.CrossoverOprMethod = CrossoverOprMethods.OnePointCrossover;
                //else if ((comboBoxCrossoverOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Two-Point")
                //    GAParameters.CrossoverOprMethod = CrossoverOprMethods.TwoPointCrossover;
                //else if ((comboBoxCrossoverOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Uniform")
                //    GAParameters.CrossoverOprMethod = CrossoverOprMethods.UniformCrossover;
                //else if ((comboBoxCrossoverOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Simulated Binary")
                //    GAParameters.CrossoverOprMethod = CrossoverOprMethods.SimulatedBinaryCrossover;

                //if ((comboBoxMutationOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Genewise")
                //    GAParameters.MutationOprMethod = MutationOprMethods.GenewiseMutation;
                //else if ((comboBoxMutationOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Selective")
                //    GAParameters.MutationOprMethod = MutationOprMethods.SelectiveMutation;
                //else if ((comboBoxMutationOpr.SelectedItem as RadComboBoxItem).Content.ToString() == "Polynomial")
                //    GAParameters.MutationOprMethod = MutationOprMethods.PolynomialMutation;

                // GA setup
                GASetup gaSetup = new GASetup(this.OptimisationTemplate);
                if (gaSetup.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    GAParameters gaParameters = gaSetup.GAParameters;
                    //gaParameters.EvaluatedSolutionsFile = Path.Combine(AircadiaProject.ProjectPath, "evaluatedSolutions.txt");
                    ((NSGAIIOptimiser)(Treatment)).GAParameters = gaParameters;
                }
            }
            else if (Treatment is SGAOptimizer)
            {
                throw new NotImplementedException("NSGAII or SGA  used a GUI to define some parameters, removing this dependencies needs to be implemented");
            }

            Treatment.Result = ActiveResult;

            status = Treatment.ApplyOn();

            return(status);
        }
Example #6
0
        public override bool Execute()
        {
            bool status = true;



            /*
             *
             * // Name of the results file
             * StudyExecutionDialog studyExecutionDialog = new StudyExecutionDialog();
             * System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(studyExecutionDialog);
             * //            studyExecutionDialog.Owner = this;
             * bool? result = studyExecutionDialog.ShowDialog(); // Show model dialog
             *
             * if (result == true)
             * {
             *  Result currentResult = new Result(studyExecutionDialog.ResultName);
             *  string fullPath = System.IO.Path.Combine("Studies", this.Name, studyExecutionDialog.ResultName + ".sdf");
             *  currentResult.DatabasePath = fullPath;
             *  this.Results.Add(currentResult);
             *  this.ActiveResult = currentResult;
             * }
             * else
             * {
             *  studyExecutionDialog.Close();
             * }
             *
             */



            string databaseFileName = Path.Combine(Project.ProjectPath, "Studies\\" + Name, Name + ".sdf"); // Microsoft SQL server compact edition file

            // Create database for optimisation results
            string connectionString;

            connectionString = String.Format("Data Source = " + databaseFileName + ";Persist Security Info=False");


            // Create tables
            var connection = new SqlCeConnection(connectionString);

            if (connection.State == ConnectionState.Closed)
            {
                connection.Open();
            }



            #region Atif
            // Create SQL statements to create tables, sqlStatement1 for OptimAllResults and sqlStatement2 for OptimGenResults
            //            this.Result.TableNames.Add("RobOptimAllResults");
            //            this.Result.TableNames.Add("RobOptimGenResults");
            string sqlStatement1 = "create table " + Name + " (";
            sqlStatement1 += "ID int, ";



            for (int i = 0; i < names.Count; i++)
            {
                sqlStatement1 += names[i] + " ";

                sqlStatement1 += "float, ";
            }


            for (int i = 0; i < robOptTemplate.DesignVariables.Count; i++)
            {
                if (!names.Contains(robOptTemplate.DesignVariables[i].Name))
                {
                    string columnHeader = robOptTemplate.DesignVariables[i].Name;
                    sqlStatement1 += columnHeader + " ";

                    sqlStatement1 += "float, ";
                }
            }


            //for (int i = 0; i < this.robOptTemplate.DesignVariables.Count(); i++)
            //{
            //    string columnHeader = this.robOptTemplate.DesignVariables[i].Name;
            //    sqlStatement1 += columnHeader + " ";
            //    sqlStatement2 += columnHeader + " ";
            //    /*
            //    if (this.robOptTemplate.DesignVariables[i].WrappedData is IntegerData)
            //    {
            //        sqlStatement1 += "int, ";
            //        sqlStatement2 += "int, ";
            //    }
            //    else if (this.robOptTemplate.DesignVariables[i].WrappedData is DoubleData)
            //    {
            //    */
            //    sqlStatement1 += "float, ";
            //    sqlStatement2 += "float, ";
            //    /*
            //    }
            //    */
            //}
            for (int i = 0; i < robOptTemplate.Objectives.Count(); i++)
            {
                string columnHeader = robOptTemplate.Objectives[i].Name;

                // Loss Function
                sqlStatement1 += columnHeader + "LF" + " ";

                /*
                 * if ((this.robOptTemplate.Objectives[i].WrappedData) is IntegerData)
                 * {
                 *  sqlStatement1 += "int, ";
                 *  sqlStatement2 += "int, ";
                 * }
                 * else if (this.robOptTemplate.Objectives[i].WrappedData is DoubleData)
                 * {
                 */
                sqlStatement1 += "float, ";

                /*
                 * }
                 */

                // Mean
                sqlStatement1 += columnHeader + "mean" + " ";

                /*
                 * if ((this.robOptTemplate.Objectives[i].WrappedData) is IntegerData)
                 * {
                 *  sqlStatement1 += "int, ";
                 *  sqlStatement2 += "int, ";
                 * }
                 * else if (this.robOptTemplate.Objectives[i].WrappedData is DoubleData)
                 * {
                 */
                sqlStatement1 += "float, ";

                /*
                 * }
                 */

                // Variance
                sqlStatement1 += columnHeader + "var" + " ";

                /*
                 * if ((this.robOptTemplate.Objectives[i].WrappedData) is IntegerData)
                 * {
                 *  sqlStatement1 += "int, ";
                 *  sqlStatement2 += "int, ";
                 * }
                 * else if (this.robOptTemplate.Objectives[i].WrappedData is DoubleData)
                 * {
                 */
                sqlStatement1 += "float, ";

                /*
                 * }
                 */
            }
            for (int i = 0; i < robOptTemplate.Constraints.Count(); i++)
            {
                string columnHeader = robOptTemplate.Constraints[i].Name;

                // Loss Function
                sqlStatement1 += columnHeader + "LF" + " ";

                /*
                 * if ((this.robOptTemplate.Constraints[i].WrappedData) is IntegerData)
                 * {
                 *  sqlStatement1 += "int, ";
                 *  sqlStatement2 += "int, ";
                 * }
                 * else if (this.robOptTemplate.Constraints[i].WrappedData is DoubleData)
                 * {
                 */
                sqlStatement1 += "float, ";

                /*
                 * }
                 */

                // Mean
                sqlStatement1 += columnHeader + "mean" + " ";

                /*
                 * if ((this.robOptTemplate.Constraints[i].WrappedData) is IntegerData)
                 * {
                 *  sqlStatement1 += "int, ";
                 *  sqlStatement2 += "int, ";
                 * }
                 * else if (this.robOptTemplate.Constraints[i].WrappedData is DoubleData)
                 * {
                 */
                sqlStatement1 += "float, ";

                /*
                 * }
                 */

                // Variance
                sqlStatement1 += columnHeader + "var" + " ";

                /*
                 * if ((this.robOptTemplate.Constraints[i].WrappedData) is IntegerData)
                 * {
                 *  sqlStatement1 += "int, ";
                 *  sqlStatement2 += "int, ";
                 * }
                 * else if (this.robOptTemplate.Constraints[i].WrappedData is DoubleData)
                 * {
                 */
                sqlStatement1 += "float, ";

                /*
                 * }
                 */
            }
            if (robOptTemplate.DesignVariables.Count() + robOptTemplate.Objectives.Count() + robOptTemplate.Constraints.Count() > 0)
            {
                sqlStatement1 = sqlStatement1.Remove(sqlStatement1.Length - 2);
            }
            sqlStatement1 += ")";

            // Create SQL statement command for "SQL Server Compact Edition"
            var command1 = new SqlCeCommand(sqlStatement1, connection);
            // Execute the SQL command
            try
            {
                command1.ExecuteNonQuery();
            }
            catch (SqlCeException sqlexception)
            {
                Console.WriteLine(sqlexception.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            #endregion Atif



            Treatment.Result = ActiveResult;

            status = Treatment.ApplyOn(StudiedComponent);



            if (Treatment.Name == "ROP" && status == true) //This is to store the results of Robust Analysis studies(RA) so that they can be visualised on the grid of the fExecuter form
            {
                //Storing variables and targets labels:
                string[,] ROPvars    = Treatment.input_options.setuplist[0] as string[, ];
                string[,] ROPtargets = Treatment.input_options.setuplist[1] as string[, ];
                int      NoROPvars       = ROPvars.GetLength(0);
                int      NoROPtargets    = ROPtargets.GetLength(0);
                string[] ROPvarsNames    = new string[NoROPvars];
                string[] ROPtargetsNames = new string[NoROPtargets];
                string   OutputString    = "";
                for (int i = 0; i < NoROPvars; i++)
                {
                    OutputString = OutputString + ROPvars[i, 0] + "(var)\t";
                }
                for (int i = 0; i < NoROPtargets - 1; i++)
                {
                    OutputString = OutputString + ROPtargets[i, 0] + "(LossFunc)\t";
                    OutputString = OutputString + ROPtargets[i, 0] + "(Mean)\t";
                    OutputString = OutputString + ROPtargets[i, 0] + "(Variance)\t";
                }
                OutputString = OutputString + ROPtargets[NoROPtargets - 1, 0] + "(LossFunc)\t";
                OutputString = OutputString + ROPtargets[NoROPtargets - 1, 0] + "(Mean)\t";
                OutputString = OutputString + ROPtargets[NoROPtargets - 1, 0] + "(Variance)\r\n";

                //Storing variables and targets values:
                //for (int i = 0; i < NoROPvars + (3 * NoROPtargets) - 1; i++)
                //{
                //    OutputString = OutputString + (Treatment as URQTreatmentOld).RobustData[0, i] + "\t";
                //}
                //OutputString = OutputString + (Treatment as URQTreatmentOld).RobustData[0, NoROPvars + 3 * NoROPtargets - 1] + "\t";


                Treatment.output_struct.output = OutputString;
            }



            if (status == true)
            {
                string CurrentDir = System.IO.Directory.GetCurrentDirectory();
                string FileName   = Name;
                if (File.Exists(CurrentDir + "\\" + FileName + ".acdstd"))
                {
                    FileName = Name + "_" + DateTime.Today.Day + "-" + DateTime.Today.Month + "-" + DateTime.Today.Year + "_" + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second;
                }
                if (File.Exists(Project.ProjectPath + "\\FuncEvalsH.txt"))
                {
                    File.Copy(Project.ProjectPath + "\\FuncEvalsH.txt", CurrentDir + "\\" + FileName + ".acdstd", false);
                }

                string output = File.ReadAllText(Project.ProjectPath + "\\FuncEvalsRob.txt");
                var    filer  = new FileStream(CurrentDir + "\\" + FileName + ".acdstd", FileMode.Append, FileAccess.Write);
                var    evals  = new StreamWriter(filer);
                evals.Write(output);
                evals.Close();
                filer.Close();


                string VisualisationCase = ((this as Study) as Study).Treatment.Name;
                if (VisualisationCase == "TradeStudy" || VisualisationCase == "rDOE" || Treatment is Aircadia.ObjectModel.Treatments.DOE.DesignOfExperiment)
                {
                    string output1 = File.ReadAllText("evaluatedSolutions.txt");
                    var    filer1  = new FileStream(CurrentDir + "\\" + FileName + ".acdstd", FileMode.Append, FileAccess.Write);
                    var    evals1  = new StreamWriter(filer1);
                    evals1.Write(output1);
                    evals1.Close();
                    filer1.Close();
                }
            }



            return(status);
        }