Beispiel #1
0
        private void UpdateMoveParameters()
        {
            IMoveMaker oldMoveMaker = MoveMaker;
            ISingleObjectiveMoveEvaluator oldMoveEvaluator = MoveEvaluator;

            ClearMoveParameters();
            if (MoveGenerator != null)
            {
                List <Type> moveTypes = MoveGenerator.GetType().GetInterfaces().Where(x => typeof(IMoveOperator).IsAssignableFrom(x)).ToList();
                foreach (Type type in moveTypes.ToList())
                {
                    if (moveTypes.Any(t => t != type && type.IsAssignableFrom(t)))
                    {
                        moveTypes.Remove(type);
                    }
                }

                var        operators        = Problem.Operators.Where(op => moveTypes.Any(m => m.IsInstanceOfType(op))).ToList();
                IMoveMaker defaultMoveMaker = operators.OfType <IMoveMaker>().FirstOrDefault();
                ISingleObjectiveMoveEvaluator defaultMoveEvaluator = operators.OfType <ISingleObjectiveMoveEvaluator>().FirstOrDefault();
                foreach (IMoveMaker moveMaker in operators.OfType <IMoveMaker>().OrderBy(op => op.Name))
                {
                    MoveMakerParameter.ValidValues.Add(moveMaker);
                }
                foreach (ISingleObjectiveMoveEvaluator moveEvaluator in operators.OfType <ISingleObjectiveMoveEvaluator>().OrderBy(op => op.Name))
                {
                    MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
                }

                if (oldMoveMaker != null)
                {
                    IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
                    if (mm != null)
                    {
                        MoveMaker = mm;
                    }
                    else
                    {
                        oldMoveMaker = null;
                    }
                }
                if (oldMoveMaker == null && defaultMoveMaker != null)
                {
                    MoveMaker = defaultMoveMaker;
                }

                if (oldMoveEvaluator != null)
                {
                    ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
                    if (me != null)
                    {
                        MoveEvaluator = me;
                    }
                    else
                    {
                        oldMoveEvaluator = null;
                    }
                }
                if (oldMoveEvaluator == null && defaultMoveEvaluator != null)
                {
                    MoveEvaluator = defaultMoveEvaluator;
                }
            }
        }
        private void ChooseMoveOperators(IMoveMaker oldMoveMaker = null, ISingleObjectiveMoveEvaluator oldMoveEvaluator = null)
        {
            if (oldMoveMaker == null)
            {
                oldMoveMaker = MoveMaker;
            }
            if (oldMoveEvaluator == null)
            {
                oldMoveEvaluator = MoveEvaluator;
            }
            MoveMakerParameter.ValidValues.Clear();
            MoveEvaluatorParameter.ValidValues.Clear();

            if (MoveGenerator != null && Problem != null)
            {
                IMoveGenerator generator = MoveGeneratorParameter.Value;
                foreach (IMoveMaker moveMaker in MoveHelper.GetCompatibleMoveMakers(generator, Problem.Operators.OfType <IOperator>()).OrderBy(x => x.Name))
                {
                    MoveMakerParameter.ValidValues.Add(moveMaker);
                }
                foreach (ISingleObjectiveMoveEvaluator moveEvaluator in MoveHelper.GetCompatibleSingleObjectiveMoveEvaluators(generator, Problem.Operators.OfType <IOperator>()).OrderBy(x => x.Name))
                {
                    MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);
                }

                if (oldMoveMaker != null)
                {
                    IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
                    if (mm != null)
                    {
                        MoveMaker = mm;
                    }
                }
                if (oldMoveEvaluator != null)
                {
                    ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
                    if (me != null)
                    {
                        MoveEvaluator = me;
                    }
                }
            }
        }
    private void ChooseMoveOperators(IMoveMaker oldMoveMaker = null, ISingleObjectiveMoveEvaluator oldMoveEvaluator = null) {
      if (oldMoveMaker == null) oldMoveMaker = MoveMaker;
      if (oldMoveEvaluator == null) oldMoveEvaluator = MoveEvaluator;
      MoveMakerParameter.ValidValues.Clear();
      MoveEvaluatorParameter.ValidValues.Clear();

      if (MoveGenerator != null && Problem != null) {
        IMoveGenerator generator = MoveGeneratorParameter.Value;
        foreach (IMoveMaker moveMaker in MoveHelper.GetCompatibleMoveMakers(generator, Problem.Operators.OfType<IOperator>()).OrderBy(x => x.Name))
          MoveMakerParameter.ValidValues.Add(moveMaker);
        foreach (ISingleObjectiveMoveEvaluator moveEvaluator in MoveHelper.GetCompatibleSingleObjectiveMoveEvaluators(generator, Problem.Operators.OfType<IOperator>()).OrderBy(x => x.Name))
          MoveEvaluatorParameter.ValidValues.Add(moveEvaluator);

        if (oldMoveMaker != null) {
          IMoveMaker mm = MoveMakerParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveMaker.GetType());
          if (mm != null) MoveMaker = mm;
        }
        if (oldMoveEvaluator != null) {
          ISingleObjectiveMoveEvaluator me = MoveEvaluatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldMoveEvaluator.GetType());
          if (me != null) MoveEvaluator = me;
        }
      }
    }