Beispiel #1
0
        // break a witness web search into a number of non-overlapping iterators
        private static WitnessWebIterator[] BuildParallelIterators(SolverInfo information, ProbabilityEngine pe, List <SolverTile> allCovered, BigInteger expectedIterations)
        {
            information.Write("Building parallel iterators");

            //information.Write("Non independent iterations = " + pe.GetNonIndependentIterations(mines));

            int minesLeft = information.GetMinesLeft();

            //the number of witnesses available
            int totalWitnesses = pe.GetIndependentWitnesses().Count + pe.GetDependentWitnesses().Count;

            // if there is only one cog then we can't lock it,so send back a single iterator
            if (pe.GetIndependentWitnesses().Count == 1 && pe.GetIndependentMines() >= minesLeft || expectedIterations.CompareTo(PARALLEL_MINIMUM) < 0 || totalWitnesses == 0)
            {
                information.Write("Only a single iterator will be used");
                WitnessWebIterator[] one = new WitnessWebIterator[1];
                one[0] = new WitnessWebIterator(information, pe.GetIndependentWitnesses(), pe.GetDependentWitnesses(), allCovered, minesLeft, information.GetTilesLeft(), -1);
                return(one);
            }

            int witMines = pe.GetIndependentWitnesses()[0].GetMinesToFind();
            int squares  = pe.GetIndependentWitnesses()[0].GetAdjacentTiles().Count;

            BigInteger bigIterations = Calculate(witMines, squares);

            int iter = (int)bigIterations;

            information.Write("The first cog has " + iter + " iterations, so parallel processing is possible");

            WitnessWebIterator[] result = new WitnessWebIterator[iter];

            for (int i = 0; i < iter; i++)
            {
                // create a iterator with a lock first got at position i
                result[i] = new WitnessWebIterator(information, pe.GetIndependentWitnesses(), pe.GetDependentWitnesses(), allCovered, minesLeft, information.GetTilesLeft(), i);
            }

            return(result);
        }
Beispiel #2
0
        public Cruncher(SolverInfo information, WitnessWebIterator iterator, List <BoxWitness> witnesses, BruteForceAnalysis bfa)
        {
            this.information = information;
            this.iterator    = iterator;            // the iterator
            this.tiles       = iterator.getTiles(); // the tiles the iterator is iterating over
            this.witnesses   = witnesses;           // the dependent witnesses (class BoxWitness) which need to be checked to see if they are satisfied

            this.bfa = bfa;

            // determine how many found mines are currently next to each tile
            this.currentFlagsTiles = new sbyte[this.tiles.Count];
            for (int i = 0; i < this.tiles.Count; i++)
            {
                this.currentFlagsTiles[i] = (sbyte)this.information.AdjacentTileInfo(this.tiles[i]).mines;
            }


            // determine how many found mines are currently next to each witness
            this.currentFlagsWitnesses = new sbyte[this.witnesses.Count];
            for (int i = 0; i < this.witnesses.Count; i++)
            {
                this.currentFlagsWitnesses[i] = (sbyte)this.information.AdjacentTileInfo(this.witnesses[i].GetTile()).mines;
            }
        }