Package sudoku

Class TableMemory


  • public class TableMemory
    extends Object
    • Field Detail

      • _offers

        private final int[] _offers
        Values of digits offered by Players. Indices represent Player. Zeros indicate currently unused slots.
      • _uniqueOffers

        private final ArrayList<TableOffer> _uniqueOffers
        Structure of unique offers given by Players.
      • _specifyFlags

        private final boolean[] _specifyFlags
        Flags indicating that all _weightFlags for a specific Player are set to true for all the _uniqueOffers. It means that the Table knows all the information it needs from that Player.
      • _requestCount

        private final int[] _requestCount
        Number of requests send to a specific Player (no feedback received).
      • _deniedMask

        private final boolean[] _deniedMask
        Mask of forbidden digits. True means, the digit causes a conflict for some Player.
      • _offerCount

        private int _offerCount
        Number of offers currently proposed by Players (offers don't have to be unique).
      • _acceptanceCount

        private int _acceptanceCount
        Number of acceptance messages received from Players. Three messages guarantee insertion of _bestOffer digit.
      • _bestOffer

        private int _bestOffer
        The offer (digit) chosen after negotiations with Players. Zero means, the offer was not chosen yet.
      • _hasFinishedIteration

        private boolean _hasFinishedIteration
        Flag - does this table had already finished current negotiations.
      • _areNegotiationsFinishedPositively

        private boolean _areNegotiationsFinishedPositively
        Does negotiations finished positively = with a consensus?
      • _iterationId

        private int _iterationId
        Id of current iteration.
    • Constructor Detail

      • TableMemory

        public TableMemory​(int sudokuSize)
    • Method Detail

      • getUniqueOfferIndex

        private int getUniqueOfferIndex​(int digit)
        Get index of a specific offer in _uniqueOffers based on a given digit. If no offer with the specified digit is present in _uniqueOffers, container size is returned.
        Parameters:
        digit - value of digit of the searched offer
        Returns:
        index of _uniqueOffers, containing the searched offer
      • getOfferCount

        public int getOfferCount()
      • incrementAcceptanceCount

        public void incrementAcceptanceCount()
      • allAcceptances

        public boolean allAcceptances()
      • resetAcceptanceCount

        public void resetAcceptanceCount()
      • isDenied

        public boolean isDenied​(int digit)
      • setBestOffer

        public void setBestOffer​(int digit)
      • getBestOffer

        public int getBestOffer()
      • setSpecifyFlag

        public void setSpecifyFlag​(int n,
                                   boolean value)
      • getSpecifyFlag

        public boolean getSpecifyFlag​(int n)
      • allSpecifyFlagTrue

        public boolean allSpecifyFlagTrue()
      • incrementRequestCount

        public void incrementRequestCount​(int n)
      • decrementRequestCount

        public void decrementRequestCount​(int n)
      • noRequestsPending

        public boolean noRequestsPending()
      • clearOffer

        public void clearOffer​(int n)
      • setOffer

        public void setOffer​(int n,
                             int digit,
                             float weight)
      • setWeight

        public void setWeight​(int n,
                              int digit,
                              float weight)
        Set weight for an offer with specified digit for a single Player. If such an offer doesn't exist, the function does nothing.
        Parameters:
        n - index of Player in internal mapping
        digit - digit of the offer
        weight - weight to be set
      • getUnknownDigits

        public int[] getUnknownDigits​(int n)
      • withdrawDigit

        public ArrayList<Integer> withdrawDigit​(int digit)
        Withdraw all offers with a digit that causes conflict for some player. If offer with specified digit does not exist, the method does nothing.
        Parameters:
        digit - value of offer causing conflict
        Returns:
        list of internal indices of Players that have their offers withdrawn
      • sumWeights

        private float sumWeights​(TableOffer o)
      • chooseBestOffer

        public void chooseBestOffer()
      • reset

        public void reset()
      • didAlreadyFinished

        public boolean didAlreadyFinished​(int iterationId)
      • finishedIterationWithDigit

        public void finishedIterationWithDigit​(int digit)
      • getIterationId

        public int getIterationId()