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());
        }
Ejemplo n.º 2
0
 private NKLandscape(NKLandscape original, Cloner cloner)
     : base(original, cloner)
 {
     random = (MersenneTwister)original.random.Clone(cloner);
     RegisterEventHandlers();
 }
Ejemplo n.º 3
0
 private NKLandscape(NKLandscape original, Cloner cloner)
   : base(original, cloner) {
   random = (MersenneTwister)original.random.Clone(cloner);
   RegisterEventHandlers();
 }