public override IOperation Apply()
        {
            BinaryVector   binaryVector = BinaryVectorParameter.ActualValue;
            OneBitflipMove move         = OneBitflipMoveParameter.ActualValue;

            BinaryVector newSolution = new BinaryVector(binaryVector);

            newSolution[move.Index] = !newSolution[move.Index];

            DoubleValue quality = KnapsackEvaluator.Apply(newSolution,
                                                          KnapsackCapacityParameter.ActualValue,
                                                          PenaltyParameter.ActualValue,
                                                          WeightsParameter.ActualValue,
                                                          ValuesParameter.ActualValue).Quality;

            double moveQuality = quality.Value;

            if (MoveQualityParameter.ActualValue == null)
            {
                MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
            }
            else
            {
                MoveQualityParameter.ActualValue.Value = moveQuality;
            }
            return(base.Apply());
        }
Ejemplo n.º 2
0
        public override IOperation Apply()
        {
            BinaryVector   binaryVector = BinaryVectorParameter.ActualValue;
            OneBitflipMove move         = OneBitflipMoveParameter.ActualValue;
            double         moveQuality  = QualityParameter.ActualValue.Value;

            if (binaryVector[move.Index])
            {
                moveQuality -= 1.0;
            }
            else
            {
                moveQuality += 1.0;
            }

            if (MoveQualityParameter.ActualValue == null)
            {
                MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
            }
            else
            {
                MoveQualityParameter.ActualValue.Value = moveQuality;
            }
            return(base.Apply());
        }
        public override IOperation Apply()
        {
            BinaryVector   binaryVector = BinaryVectorParameter.ActualValue;
            OneBitflipMove move         = OneBitflipMoveParameter.ActualValue;
            BoolMatrix     interactions = GeneInteractionsParameter.ActualValue;
            DoubleArray    weights      = WeightsParameter.ActualValue;
            int            seed         = InteractionSeedParameter.ActualValue.Value;
            double         moveQuality  = QualityParameter.ActualValue.Value;
            int            q            = QParameter.ActualValue.Value;
            double         p            = PParameter.ActualValue.Value;

            List <int> affectedFitnessComponents = new List <int>();

            for (int c = 0; c < interactions.Columns; c++)
            {
                if (interactions[move.Index, c])
                {
                    affectedFitnessComponents.Add(c);
                }
            }
            BinaryVector moved = new BinaryVector(binaryVector);

            MovedBinaryVectorParameter.ActualValue = moved;
            moved[move.Index] = !moved[move.Index];
            if (affectedFitnessComponents.Count * 2 > interactions.Columns)
            {
                double[] f_i;
                moveQuality = NKLandscape.Evaluate(moved, interactions, weights, seed, out f_i, q, p);
            }
            else
            {
                long     x = NKLandscape.Encode(binaryVector);
                long     y = NKLandscape.Encode(moved);
                long[]   g = NKLandscape.Encode(interactions);
                double[] w = NKLandscape.Normalize(weights);
                foreach (var c in affectedFitnessComponents)
                {
                    moveQuality -= w[c % w.Length] * NKLandscape.F_i(x, c, g[c], seed, q, p);
                    moveQuality += w[c % w.Length] * NKLandscape.F_i(y, c, g[c], seed, q, p);
                }
            }

            if (MoveQualityParameter.ActualValue == null)
            {
                MoveQualityParameter.ActualValue = new DoubleValue(moveQuality);
            }
            else
            {
                MoveQualityParameter.ActualValue.Value = moveQuality;
            }
            return(base.Apply());
        }