Changeset 14526 for branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4/SingleObjectiveGoalSeekingProblem.cs
- Timestamp:
- 12/22/16 16:52:32 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4/SingleObjectiveGoalSeekingProblem.cs
r14379 r14526 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Data; 28 29 using HeuristicLab.Encodings.RealVectorEncoding; 29 30 using HeuristicLab.Optimization; … … 38 39 public sealed class SingleObjectiveGoalSeekingProblem : SingleObjectiveBasicProblem<RealVectorEncoding>, IGoalSeekingProblem { 39 40 #region parameter names 40 private const string ModifiableDatasetParameterName = "Dataset";41 41 private const string InputsParameterName = "Inputs"; 42 42 private const string GoalsParameterName = "Goals"; … … 136 136 public SingleObjectiveGoalSeekingProblem() { 137 137 dataset = new ModifiableDataset(); 138 Parameters.Add(new ValueParameter<IDataset>(ModifiableDatasetParameterName, dataset) { Hidden = true });139 138 Parameters.Add(new ValueParameter<CheckedItemList<InputParameter>>(InputsParameterName)); 140 139 Parameters.Add(new ValueParameter<CheckedItemList<GoalParameter>>(GoalsParameterName)); … … 161 160 return quality; 162 161 } 162 163 public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) { 164 var zipped = individuals.Zip(qualities, (ind, qual) => new { Individual = ind, Quality = qual }).OrderBy(x => x.Quality); 165 var best = Maximization ? zipped.Last() : zipped.First(); 166 var realVector = best.Individual.RealVector(); 167 const string resultName = "Best Solution"; 168 169 var columnNames = new List<string>(); 170 foreach (var goal in ActiveGoals) { 171 columnNames.Add(goal.Name); 172 columnNames.Add(goal.Name + " (estimated)"); 173 } 174 foreach (var input in ActiveInputs) { 175 columnNames.Add(input.Name); 176 columnNames.Add(input.Name + " (estimated)"); 177 columnNames.Add(input.Name + " (deviation)"); 178 } 179 180 var m = new DoubleMatrix(1, columnNames.Count) { ColumnNames = columnNames }; 181 int i = 0; 182 183 var goals = ActiveGoals.Zip(GetEstimatedGoalValues(realVector, round: true), 184 (goal, value) => new { TargetValue = goal.Goal, EstimatedValue = value }); 185 186 foreach (var goal in goals) { 187 m[0, i] = goal.TargetValue; 188 m[0, i + 1] = goal.EstimatedValue; 189 i += 2; 190 } 191 192 var inputs = ActiveInputs.Zip(realVector, 193 (input, value) => new { ActualValue = input.Value, EstimatedValue = value }); 194 195 foreach (var input in inputs) { 196 m[0, i] = input.ActualValue; 197 m[0, i + 1] = input.EstimatedValue; 198 m[0, i + 2] = m[0, i] - m[0, i + 1]; 199 i += 3; 200 } 201 202 if (!results.ContainsKey(resultName)) { 203 results.Add(new Result(resultName, m)); 204 } else { 205 results[resultName].Value = m; 206 } 207 208 base.Analyze(individuals, qualities, results, random); 209 } 210 163 211 #region event handlers 164 165 212 private void RegisterEvents() { 166 213 ModelsParameter.Value.ItemsAdded += ModelCollection_ItemsChanged;
Note: See TracChangeset
for help on using the changeset viewer.