[4188] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.ComponentModel;
|
---|
| 4 | using System.Data;
|
---|
| 5 | using System.Drawing;
|
---|
| 6 | using System.Linq;
|
---|
| 7 | using System.Text;
|
---|
| 8 | using System.Windows.Forms;
|
---|
| 9 |
|
---|
| 10 | namespace HeuristicLab.VS2010Wizards {
|
---|
| 11 | public partial class ProblemWizardForm : Form {
|
---|
| 12 | public string ProblemName {
|
---|
| 13 | get;
|
---|
| 14 | private set;
|
---|
| 15 | }
|
---|
| 16 | public string ProblemDescription {
|
---|
| 17 | get;
|
---|
| 18 | private set;
|
---|
| 19 | }
|
---|
[4214] | 20 | public bool IsSingleObjective {
|
---|
| 21 | get;
|
---|
| 22 | private set;
|
---|
| 23 | }
|
---|
[4188] | 24 | public bool IsMultiObjective {
|
---|
| 25 | get;
|
---|
| 26 | private set;
|
---|
| 27 | }
|
---|
| 28 | public string ParameterProperties {
|
---|
| 29 | get;
|
---|
| 30 | private set;
|
---|
| 31 | }
|
---|
| 32 | public string Properties {
|
---|
| 33 | get;
|
---|
| 34 | private set;
|
---|
| 35 | }
|
---|
| 36 | public string ParameterInitializers {
|
---|
| 37 | get;
|
---|
| 38 | private set;
|
---|
| 39 | }
|
---|
[4214] | 40 | public string EvaluatorType {
|
---|
| 41 | get;
|
---|
| 42 | private set;
|
---|
| 43 | }
|
---|
| 44 | public string SolutionCreatorType {
|
---|
| 45 | get;
|
---|
| 46 | private set;
|
---|
| 47 | }
|
---|
| 48 | public string ProblemTypeImplementation {
|
---|
| 49 | get;
|
---|
| 50 | private set;
|
---|
| 51 | }
|
---|
| 52 | public string ProblemSpecificParameterProperties {
|
---|
| 53 | get;
|
---|
| 54 | private set;
|
---|
| 55 | }
|
---|
| 56 | public string ProblemSpecificProperties {
|
---|
| 57 | get;
|
---|
| 58 | private set;
|
---|
| 59 | }
|
---|
| 60 | public string ProblemSpecificParameterInitializers {
|
---|
| 61 | get;
|
---|
| 62 | private set;
|
---|
| 63 | }
|
---|
[4188] | 64 |
|
---|
| 65 | public ProblemWizardForm() {
|
---|
| 66 | InitializeComponent();
|
---|
[4214] | 67 | IsSingleObjective = singleObjectiveCheckBox.Checked;
|
---|
| 68 | IsMultiObjective = multiObjectiveCheckBox.Checked;
|
---|
| 69 | EvaluatorType = evaluatorTypeTextBox.Text;
|
---|
| 70 | SolutionCreatorType = solutionCreatorTypeTextBox.Text;
|
---|
[4188] | 71 | }
|
---|
| 72 |
|
---|
| 73 | private void finishButton_Click(object sender, System.EventArgs e) {
|
---|
| 74 | SetProperties();
|
---|
| 75 | DialogResult = System.Windows.Forms.DialogResult.OK;
|
---|
| 76 | Close();
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | private void cancelButton_Click(object sender, System.EventArgs e) {
|
---|
| 80 | DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
---|
| 81 | Close();
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | private void SetProperties() {
|
---|
| 85 | ProblemName = problemNameTextBox.Text;
|
---|
| 86 | ProblemDescription = problemDescriptionTextBox.Text;
|
---|
[4214] | 87 | IsMultiObjective = multiObjectiveCheckBox.Checked;
|
---|
| 88 | ParameterProperties = parametersControl.GetParameterProperties("public");
|
---|
[4188] | 89 | Properties = parametersControl.GetProperties("public");
|
---|
| 90 | ParameterInitializers = parametersControl.GetInitializers();
|
---|
[4214] | 91 |
|
---|
| 92 | if (IsMultiObjective && IsSingleObjective) {
|
---|
| 93 | ProblemTypeImplementation = "ISingleObjectiveProblem, IMultiObjectiveProblem";
|
---|
| 94 | } else if (IsMultiObjective) {
|
---|
| 95 | ProblemTypeImplementation = "IMultiObjectiveProblem";
|
---|
| 96 | } else if (IsSingleObjective)
|
---|
| 97 | ProblemTypeImplementation = "ISingleObjectiveProblem";
|
---|
| 98 |
|
---|
| 99 | ProblemSpecificParameterProperties = GetParamProps();
|
---|
| 100 | ProblemSpecificProperties = GetProps();
|
---|
| 101 | ProblemSpecificParameterInitializers = GetParamInitializers();
|
---|
[4188] | 102 | }
|
---|
| 103 |
|
---|
[4214] | 104 | private string GetParamProps() {
|
---|
| 105 | StringBuilder builder = new StringBuilder();
|
---|
| 106 | if (IsSingleObjective) {
|
---|
| 107 | builder.Append(@"public OptionalValueParameter<DoubleValue> BestKnownQualityParameter {
|
---|
| 108 | get { return (OptionalValueParameter<DoubleValue>)Parameters[""BestKnownQuality""]; }
|
---|
| 109 | }
|
---|
| 110 | IParameter ISingleObjectiveProblem.BestKnownQualityParameter {
|
---|
| 111 | get { return BestKnownQualityParameter; }
|
---|
| 112 | }");
|
---|
| 113 | builder.Append(Environment.NewLine);
|
---|
| 114 | builder.Append(@"public ValueParameter<BoolValue> MaximizationParameter {
|
---|
| 115 | get { return (ValueParameter<BoolValue>)Parameters[""Maximization""]; }
|
---|
| 116 | }
|
---|
| 117 | IParameter ISingleObjectiveProblem.MaximizationParameter {
|
---|
| 118 | get { return MaximizationParameter; }
|
---|
| 119 | }");
|
---|
| 120 | builder.Append(Environment.NewLine);
|
---|
| 121 | }
|
---|
| 122 | if (IsMultiObjective) {
|
---|
| 123 | builder.Append(@" public ValueParameter<BoolArray> MultiObjectiveMaximizationParameter {
|
---|
| 124 | get { return (ValueParameter<BoolArray>)Parameters[""MultiObjectiveMaximization""]; }
|
---|
| 125 | }
|
---|
| 126 | IParameter IMultiObjectiveProblem.MaximizationParameter {
|
---|
| 127 | get { return MultiObjectiveMaximizationParameter; }
|
---|
| 128 | }");
|
---|
| 129 | builder.Append(Environment.NewLine);
|
---|
| 130 | }
|
---|
| 131 | builder.Append(@"public ValueParameter<" + SolutionCreatorType + @"> SolutionCreatorParameter {
|
---|
| 132 | get { return (ValueParameter<" + SolutionCreatorType + @">)Parameters[""SolutionCreator""]; }
|
---|
| 133 | }
|
---|
| 134 | IParameter IProblem.SolutionCreatorParameter {
|
---|
| 135 | get { return SolutionCreatorParameter; }
|
---|
| 136 | }
|
---|
| 137 | public ValueParameter<" + EvaluatorType + @"> EvaluatorParameter {
|
---|
| 138 | get { return (ValueParameter<" + EvaluatorType + @">)Parameters[""Evaluator""]; }
|
---|
| 139 | }
|
---|
| 140 | IParameter IProblem.EvaluatorParameter {
|
---|
| 141 | get { return EvaluatorParameter; }
|
---|
| 142 | }");
|
---|
| 143 | return builder.ToString();
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | private string GetProps() {
|
---|
| 147 | StringBuilder builder = new StringBuilder();
|
---|
| 148 | builder.Append(@"public " + SolutionCreatorType + @" SolutionCreator {
|
---|
| 149 | get { return SolutionCreatorParameter.Value; }
|
---|
| 150 | set { SolutionCreatorParameter.Value = value; }
|
---|
| 151 | }
|
---|
| 152 | ISolutionCreator IProblem.SolutionCreator {
|
---|
| 153 | get { return SolutionCreatorParameter.Value; }
|
---|
| 154 | }
|
---|
| 155 | public " + EvaluatorType + @" Evaluator {
|
---|
| 156 | get { return EvaluatorParameter.Value; }
|
---|
| 157 | set { EvaluatorParameter.Value = value; }
|
---|
| 158 | }");
|
---|
| 159 | builder.Append(Environment.NewLine);
|
---|
| 160 | if (IsSingleObjective) {
|
---|
| 161 | builder.Append(@"ISingleObjectiveEvaluator ISingleObjectiveProblem.Evaluator {
|
---|
| 162 | get { return EvaluatorParameter.Value; }
|
---|
| 163 | }");
|
---|
| 164 | builder.Append(Environment.NewLine);
|
---|
| 165 | }
|
---|
| 166 | if (IsMultiObjective) {
|
---|
| 167 | builder.Append(@"IMultiObjectiveEvaluator IMultiObjectiveProblem.Evaluator {
|
---|
| 168 | get { return EvaluatorParameter.Value; }
|
---|
| 169 | }");
|
---|
| 170 | builder.Append(Environment.NewLine);
|
---|
| 171 | }
|
---|
| 172 | builder.Append(@"IEvaluator IProblem.Evaluator {
|
---|
| 173 | get { return EvaluatorParameter.Value; }
|
---|
| 174 | }");
|
---|
| 175 | builder.Append(Environment.NewLine);
|
---|
| 176 | if (IsSingleObjective) {
|
---|
| 177 | builder.Append(@"public DoubleValue BestKnownQuality {
|
---|
| 178 | get { return BestKnownQualityParameter.Value; }
|
---|
| 179 | set { BestKnownQualityParameter.Value = value; }
|
---|
| 180 | }");
|
---|
| 181 | builder.Append(Environment.NewLine);
|
---|
| 182 | }
|
---|
| 183 | return builder.ToString();
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | private string GetParamInitializers() {
|
---|
| 187 | StringBuilder builder = new StringBuilder();
|
---|
| 188 | if (IsSingleObjective) {
|
---|
| 189 | builder.Append(@"Parameters.Add(new ValueParameter<BoolValue>(""Maximization"", ""TODO: Set to the false for minimization, true for maximization and add a description."", new BoolValue(false)));");
|
---|
| 190 | builder.Append(Environment.NewLine);
|
---|
| 191 | }
|
---|
| 192 | if (IsMultiObjective) {
|
---|
| 193 | builder.Append("// TODO: Change the default value to the number of objectives." + Environment.NewLine);
|
---|
| 194 | builder.Append(@"Parameters.Add(new ValueParameter<BoolArray>(""MultiObjectiveMaximization"", ""Set to false as the error of the regression model should be minimized."", new BoolArray(new bool[] {false, false})));");
|
---|
| 195 | builder.Append(Environment.NewLine);
|
---|
| 196 | }
|
---|
| 197 | builder.Append("// TODO: Add a default solution creator." + Environment.NewLine);
|
---|
| 198 | builder.Append("Parameters.Add(new ValueParameter<" + SolutionCreatorType + ">(\"SolutionCreator\", \"The operator which should be used to create new solutions.\", null));");
|
---|
| 199 | builder.Append(Environment.NewLine);
|
---|
| 200 | builder.Append("//TODO: Add a default evaluator." + Environment.NewLine);
|
---|
| 201 | builder.Append("Parameters.Add(new ValueParameter<" + EvaluatorType + ">(\"Evaluator\", \"The operator which should be used to evaluate solutions.\", null));");
|
---|
| 202 | builder.Append(Environment.NewLine);
|
---|
| 203 | if (IsSingleObjective) {
|
---|
| 204 | builder.Append("Parameters.Add(new OptionalValueParameter<DoubleValue>(\"BestKnownQuality\", \"The quality of the best known solution.\"));");
|
---|
| 205 | builder.Append(Environment.NewLine);
|
---|
| 206 | }
|
---|
| 207 | return builder.ToString();
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[4188] | 210 | private void nextButton_Click(object sender, EventArgs e) {
|
---|
| 211 | page1Panel.Visible = false;
|
---|
| 212 | page2Panel.Visible = true;
|
---|
| 213 | nextButton.Enabled = false;
|
---|
| 214 | previousButton.Enabled = true;
|
---|
| 215 | }
|
---|
| 216 |
|
---|
| 217 | private void previousButton_Click(object sender, EventArgs e) {
|
---|
| 218 | page2Panel.Visible = false;
|
---|
| 219 | page1Panel.Visible = true;
|
---|
| 220 | previousButton.Enabled = false;
|
---|
| 221 | nextButton.Enabled = true;
|
---|
| 222 | }
|
---|
[4214] | 223 |
|
---|
| 224 | private void singleObjectiveCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 225 | IsSingleObjective = singleObjectiveCheckBox.Checked;
|
---|
| 226 | nextButton.Enabled = IsSingleObjective || IsMultiObjective;
|
---|
| 227 | finishButton.Enabled = nextButton.Enabled;
|
---|
| 228 | }
|
---|
| 229 | private void multiObjectiveCheckBox_CheckedChanged(object sender, EventArgs e) {
|
---|
| 230 | IsMultiObjective = multiObjectiveCheckBox.Checked;
|
---|
| 231 | nextButton.Enabled = IsSingleObjective || IsMultiObjective;
|
---|
| 232 | finishButton.Enabled = nextButton.Enabled;
|
---|
| 233 | }
|
---|
| 234 | private void problemNameTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 235 | ProblemName = problemNameTextBox.Text.Trim();
|
---|
| 236 | nextButton.Enabled = ProblemName != string.Empty;
|
---|
| 237 | }
|
---|
| 238 | private void evaluatorTypeTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 239 | EvaluatorType = evaluatorTypeTextBox.Text.Trim();
|
---|
| 240 | nextButton.Enabled = EvaluatorType != string.Empty;
|
---|
| 241 | }
|
---|
| 242 | private void solutionCreatorTypeTextBox_TextChanged(object sender, EventArgs e) {
|
---|
| 243 | SolutionCreatorType = solutionCreatorTypeTextBox.Text.Trim();
|
---|
| 244 | nextButton.Enabled = SolutionCreatorType != string.Empty;
|
---|
| 245 | }
|
---|
[4188] | 246 | }
|
---|
| 247 | }
|
---|