Esempio n. 1
0
        private SatConfiguration GetRandomNeighbor(SimulatedAnnealingSolver solverInstance, SatConfiguration currentConfiguration)
        {
            var flipIndex          = random.Next(0, solverInstance.SatInstance.Literals.Count);
            var triedConfiguration = new SatConfiguration(currentConfiguration);

            triedConfiguration.FlipValuation(flipIndex);

            return(triedConfiguration);
        }
Esempio n. 2
0
        private SatConfiguration GetBetterSatisfiabilityNeighbor(SimulatedAnnealingSolver solverInstance, SatConfiguration currentConfiguration)
        {
            var candidateIndex = currentConfiguration.IndexOfRandomToImproveSatisfiability(random);

            if (candidateIndex > 0)
            {
                var triedConfiguration = new SatConfiguration(currentConfiguration);
                triedConfiguration.FlipValuation(candidateIndex);
                return(triedConfiguration);
            }
            else
            {
                return(GetBetterScoreNeighbor(solverInstance, currentConfiguration));
            }
        }
Esempio n. 3
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);
        }