Esempio n. 1
0
        public override bool Try(SimulatedAnnealingSolver solverInstance, ref SatConfiguration currentConfiguration)
        {
            SatConfiguration triedConfiguration;

            double randomChoice = random.NextDouble();

            if (randomChoice < randomNeighborProb)
            {
                triedConfiguration = GetRandomNeighbor(solverInstance, currentConfiguration);
            }
            else if (randomChoice < randomNeighborProb + randomNewProb)
            {
                triedConfiguration = SatConfiguration.RandomConfiguration(solverInstance.SatInstance, random);
            }
            else if (randomChoice < randomNeighborProb + randomNewProb + improveScoreProb)
            {
                triedConfiguration = GetBetterScoreNeighbor(solverInstance, currentConfiguration);
            }
            else
            {
                triedConfiguration = GetBetterSatisfiabilityNeighbor(solverInstance, currentConfiguration);
            }

            triedConfiguration.Score = solverInstance.Options.ScoreStrategy.CalculateScore(triedConfiguration, solverInstance);
            if (Accept(triedConfiguration, currentConfiguration, solverInstance.CurrentTemperature))
            {
                currentConfiguration = triedConfiguration;
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        private SatConfiguration GetBetterScoreNeighbor(SimulatedAnnealingSolver solverInstance, SatConfiguration currentConfiguration)
        {
            var triedConfiguration = new SatConfiguration(currentConfiguration);

            var flipIndex = currentConfiguration.IndexOfRandomToImproveScore(random);

            //Nothing to improve (all valuations set to 1), reset the configuration entirely
            if (flipIndex < 0)
            {
                triedConfiguration = SatConfiguration.RandomConfiguration(solverInstance.SatInstance, random);
            }
            else
            {
                triedConfiguration.FlipValuation(flipIndex);
            }
            return(triedConfiguration);
        }
Esempio n. 3
0
 public SatConfiguration GetStartingPosition(SimulatedAnnealingSolver solverInstance)
 {
     return(SatConfiguration.RandomConfiguration(solverInstance.SatInstance, random));
 }