Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/09/16 14:55:10 (8 years ago)
Author:
bburlacu
Message:

#2679: Use an item list for models in the goal seeking problems instead of an item collection. Update encoding instead of creating a new one when inputs are changed.

Location:
branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4/GoalSeekingUtil.cs

    r14336 r14379  
    1 using System;
     1#region License Information
     2/* HeuristicLab
     3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     4 *
     5 * This file is part of HeuristicLab.
     6 *
     7 * HeuristicLab is free software: you can redistribute it and/or modify
     8 * it under the terms of the GNU General Public License as published by
     9 * the Free Software Foundation, either version 3 of the License, or
     10 * (at your option) any later version.
     11 *
     12 * HeuristicLab is distributed in the hope that it will be useful,
     13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 * GNU General Public License for more details.
     16 *
     17 * You should have received a copy of the GNU General Public License
     18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
     19 */
     20#endregion
     21
     22using System;
    223using System.Collections.Generic;
    324using System.Linq;
     
    6182      }
    6283      return encoding;
     84    }
     85
     86    internal static void UpdateEncoding(RealVectorEncoding encoding, IEnumerable<InputParameter> inputParameters) {
     87      encoding.Length = inputParameters.Count();
     88      encoding.Bounds = new DoubleMatrix(encoding.Length, 2);
     89      encoding.Bounds.RowNames = inputParameters.Select(x => x.Name);
     90      encoding.Bounds.ColumnNames = new[] { "Min.", "Max." };
     91
     92      int i = 0;
     93      foreach (var parameter in inputParameters) {
     94        encoding.Bounds[i, 0] = parameter.Min;
     95        encoding.Bounds[i, 1] = parameter.Max;
     96        ++i;
     97      }
    6398    }
    6499
  • branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4/MultiObjectiveGoalSeekingProblem.cs

    r14338 r14379  
    5353      get { return (IValueParameter<CheckedItemList<GoalParameter>>)Parameters[GoalsParameterName]; }
    5454    }
    55     public IFixedValueParameter<ItemCollection<IRegressionModel>> ModelsParameter {
    56       get { return (IFixedValueParameter<ItemCollection<IRegressionModel>>)Parameters[ModelsParameterName]; }
     55    public IFixedValueParameter<ItemList<IRegressionModel>> ModelsParameter {
     56      get { return (IFixedValueParameter<ItemList<IRegressionModel>>)Parameters[ModelsParameterName]; }
    5757    }
    5858    public IFixedValueParameter<DoubleValue> QualitySumCutoffParameter {
     
    154154      Parameters.Add(new ValueParameter<CheckedItemList<InputParameter>>(InputsParameterName));
    155155      Parameters.Add(new ValueParameter<CheckedItemList<GoalParameter>>(GoalsParameterName));
    156       Parameters.Add(new FixedValueParameter<ItemCollection<IRegressionModel>>(ModelsParameterName, new ItemCollection<IRegressionModel>()));
     156      Parameters.Add(new FixedValueParameter<ItemList<IRegressionModel>>(ModelsParameterName, new ItemList<IRegressionModel>()));
    157157      Parameters.Add(new FixedValueParameter<DoubleValue>(QualitySumCutoffParameterName, new DoubleValue(0.2)));
    158158      QualitySumCutoffParameter.Hidden = true;
     
    228228        for (int j = 0; j < activeParameters.Count * 3; j += 3) {
    229229          int k = j + offset;
    230           rowValues[k] = 0; // TODO: figure this out and fix
     230          rowValues[k] = activeParameters[j / 3].Value;
    231231          rowValues[k + 1] = vector[j / 3];
    232232          rowValues[k + 2] = rowValues[k + 1] - rowValues[k];
     
    261261    }
    262262
    263     private void ModelCollection_ItemsChanged(object sender, CollectionItemsChangedEventArgs<IRegressionModel> e) {
     263    private void ModelCollection_ItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<IRegressionModel>> e) {
    264264      if (e.Items == null || !e.Items.Any()) return;
    265265      GoalSeekingUtil.UpdateInputs(InputsParameter.Value, Models, InputParameterChanged);
    266       Encoding = GoalSeekingUtil.CreateEncoding(ActiveInputs);
     266      GoalSeekingUtil.UpdateEncoding(Encoding, ActiveInputs);
    267267      dataset = Inputs.Any() ? new ModifiableDataset(Inputs.Select(x => x.Name), Inputs.Select(x => new List<double> { x.Value })) : new ModifiableDataset();
    268268      GoalSeekingUtil.UpdateTargets(GoalsParameter.Value, Models, GoalParameterChanged);
     
    275275      if (inputs.ItemChecked(inputParameter) != inputParameter.Active)
    276276        inputs.SetItemCheckedState(inputParameter, inputParameter.Active);
    277       Encoding = GoalSeekingUtil.CreateEncoding(ActiveInputs);
     277      GoalSeekingUtil.UpdateEncoding(Encoding, ActiveInputs);
    278278    }
    279279
  • branches/HeuristicLab.GoalSeekingProblem/HeuristicLab.GoalSeekingProblem/3.4/SingleObjectiveGoalSeekingProblem.cs

    r14338 r14379  
    5151      get { return (IValueParameter<CheckedItemList<GoalParameter>>)Parameters[GoalsParameterName]; }
    5252    }
    53     public IFixedValueParameter<ItemCollection<IRegressionModel>> ModelsParameter {
    54       get { return (IFixedValueParameter<ItemCollection<IRegressionModel>>)Parameters[ModelsParameterName]; }
     53    public IFixedValueParameter<ItemList<IRegressionModel>> ModelsParameter {
     54      get { return (IFixedValueParameter<ItemList<IRegressionModel>>)Parameters[ModelsParameterName]; }
    5555    }
    5656    #endregion
     
    139139      Parameters.Add(new ValueParameter<CheckedItemList<InputParameter>>(InputsParameterName));
    140140      Parameters.Add(new ValueParameter<CheckedItemList<GoalParameter>>(GoalsParameterName));
    141       Parameters.Add(new FixedValueParameter<ItemCollection<IRegressionModel>>(ModelsParameterName, new ItemCollection<IRegressionModel>()));
     141      Parameters.Add(new FixedValueParameter<ItemList<IRegressionModel>>(ModelsParameterName, new ItemList<IRegressionModel>()));
    142142      EncodingParameter.Hidden = true;
    143143      EvaluatorParameter.Hidden = true;
     
    176176    }
    177177
    178     private void ModelCollection_ItemsChanged(object sender, CollectionItemsChangedEventArgs<IRegressionModel> e) {
     178    private void ModelCollection_ItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<IRegressionModel>> e) {
    179179      if (e.Items == null || !e.Items.Any()) return;
    180180      GoalSeekingUtil.UpdateInputs(InputsParameter.Value, Models, InputParameterChanged);
    181       Encoding = GoalSeekingUtil.CreateEncoding(ActiveInputs);
     181      GoalSeekingUtil.UpdateEncoding(Encoding, ActiveInputs);
    182182      dataset = Inputs.Any() ? new ModifiableDataset(Inputs.Select(x => x.Name), Inputs.Select(x => new List<double> { x.Value })) : new ModifiableDataset();
    183183      GoalSeekingUtil.UpdateTargets(GoalsParameter.Value, Models, GoalParameterChanged);
     
    190190      if (inputs.ItemChecked(inputParameter) != inputParameter.Active)
    191191        inputs.SetItemCheckedState(inputParameter, inputParameter.Active);
    192       Encoding = GoalSeekingUtil.CreateEncoding(ActiveInputs);
     192      GoalSeekingUtil.UpdateEncoding(Encoding, ActiveInputs);
    193193    }
    194194
Note: See TracChangeset for help on using the changeset viewer.