Esempio n. 1
0
        public float CalculateScore(SatConfiguration configuration, SimulatedAnnealingSolver solver)
        {
            //Base score is the optimalization value
            float score = configuration.GetOptimalizationValue();

            //Make the score negative if it is unsatisfiable
            if (!configuration.IsSatisfiable())
            {
                score -= configuration.Instance.GetSumOfWeights();
            }

            //Penalize the score further based on the number of unsatisfied clauses
            score -= configuration.NumberOfUnsatisfiedClauses() * solver.Options.PenaltyMultiplier;
            return(score);
        }
Esempio n. 2
0
        private bool RunSolutionLoop()
        {
            while (!Options.FrozenStrategy.Frozen(this))
            {
                AcceptedDuringEquilibrium = 0;
                EquilibriumSteps          = 0;

                while (Options.EquilibriumStrategy.Equilibrium(this))
                {
                    EquilibriumSteps++;
                    if (Options.SavePlotInfo)
                    {
                        movesHistory.Add(new DataPoint((int)NumberOfSteps + EquilibriumSteps, currentConfiguration.GetOptimalizationValue()));
                    }
                    //Try to accept a new state
                    if (Options.TryStrategy.Try(this, ref currentConfiguration))
                    {
                        AcceptedDuringEquilibrium++;
                    }
                    //Check if new maximum has been found
                    if (currentConfiguration.GetOptimalizationValue() > BestConfiguration.GetOptimalizationValue() && currentConfiguration.IsSatisfiable())
                    {
                        BestConfiguration        = currentConfiguration;
                        bestConfigurationFoundAt = NumberOfSteps + (ulong)EquilibriumSteps;
                    }
                }
                CurrentTemperature = Options.CoolStrategy.Cool(this);
                NumberOfSteps     += (ulong)EquilibriumSteps;
            }

            if (BestConfiguration.IsSatisfiable())
            {
                return(true);
            }
            return(false);
        }