protected override void EvaluateMove()
        {
            PotvinCustomerRelocationMove move = CustomerRelocationMoveParameter.ActualValue;

            PotvinEncoding newSolution = CustomerRelocationMoveParameter.ActualValue.Individual.Clone() as PotvinEncoding;

            PotvinCustomerRelocationMoveMaker.Apply(newSolution, move, ProblemInstance);

            UpdateEvaluation(newSolution);

            //Apply memory, only if move is worse
            if (MoveQualityParameter.ActualValue.Value >= QualityParameter.ActualValue.Value)
            {
                VariableCollection memory = MemoriesParameter.ActualValue;
                string             key    = AdditionFrequencyMemoryKeyParameter.Value.Value;

                if (memory != null && memory.ContainsKey(key))
                {
                    ItemDictionary <PotvinCustomerRelocationMoveAttribute, IntValue> additionFrequency =
                        memory[key].Value as ItemDictionary <PotvinCustomerRelocationMoveAttribute, IntValue>;
                    PotvinCustomerRelocationMoveAttribute attr = new PotvinCustomerRelocationMoveAttribute(0, move.Tour, move.City);
                    if (additionFrequency.ContainsKey(attr))
                    {
                        int    frequency = additionFrequency[attr].Value;
                        double quality   = MoveQualityParameter.ActualValue.Value;

                        MoveQualityParameter.ActualValue.Value +=
                            LambdaParameter.Value.Value * quality * frequency;
                    }
                }
            }
        }
 public static void SetVariable(string name, Variable value)
 {
     if (_variables.ContainsKey(name))
     {
         _variables[name] = value;
     }
     else
     {
         _variables.Add(name, value);
     }
 }
Пример #3
0
 public void SetVariable(string name, Variable value)
 {
     if (_variables.ContainsKey(name))
     {
         _variables[name] = value;
     }
     else
     {
         value.OnValueChange += DataChange;
         _variables.Add(name, value);
     }
 }
        public static void Map(ref ParametersCollection parameters, VariableCollection variables)
        {
            if (parameters is null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (variables is null)
            {
                throw new ArgumentNullException(nameof(variables));
            }

            foreach (var parameter in parameters)
            {
                if (variables.ContainsKey(parameter.Name))
                {
                    variables.Remove(parameter.Name);
                }
                variables.Add(parameter.Name, parameter.Value.Infer());
            }
        }
        protected override void PerformMove()
        {
            PotvinCustomerRelocationMove move = CustomerRelocationMoveParameter.ActualValue;

            PotvinEncoding newSolution = move.Individual.Clone() as PotvinEncoding;

            Apply(newSolution, move, ProblemInstance);
            newSolution.Repair();
            VRPToursParameter.ActualValue = newSolution;

            //reset move quality
            VRPEvaluation eval = ProblemInstance.Evaluate(newSolution);

            MoveQualityParameter.ActualValue.Value = eval.Quality;

            //update memory
            VariableCollection memory = MemoriesParameter.ActualValue;
            string             key    = AdditionFrequencyMemoryKeyParameter.Value.Value;

            if (memory != null)
            {
                if (!memory.ContainsKey(key))
                {
                    memory.Add(new Variable(key,
                                            new ItemDictionary <PotvinCustomerRelocationMoveAttribute, IntValue>()));
                }
                ItemDictionary <PotvinCustomerRelocationMoveAttribute, IntValue> additionFrequency =
                    memory[key].Value as ItemDictionary <PotvinCustomerRelocationMoveAttribute, IntValue>;

                PotvinCustomerRelocationMoveAttribute attr = new PotvinCustomerRelocationMoveAttribute(0, move.Tour, move.City);
                if (!additionFrequency.ContainsKey(attr))
                {
                    additionFrequency[attr] = new IntValue(0);
                }

                additionFrequency[attr].Value++;
            }
        }
Пример #6
0
 /// <summary>Determines whether the <see cref="T:System.Collections.Generic.IDictionary`2" /> contains an element with the specified key.</summary>
 /// <param name="key">The key to locate in the <see cref="T:System.Collections.Generic.IDictionary`2" />.</param>
 /// <returns>
 /// <see langword="true" /> if the <see cref="T:System.Collections.Generic.IDictionary`2" /> contains an element with the key; otherwise, <see langword="false" />.</returns>
 /// <exception cref="T:System.ArgumentNullException">
 /// <paramref name="key" /> is <see langword="null" />.</exception>
 public bool ContainsKey(string name)
 {
     return(_collection.ContainsKey(name));
 }
Пример #7
0
 public bool Contains(string variableName)
 {
     Contract.Requires <ArgumentException>(!String.IsNullOrEmpty(variableName));
     return(variables.ContainsKey(variableName));
 }