Package sudoku
Class TableMemory
- java.lang.Object
-
- sudoku.TableMemory
-
public class TableMemory extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TableMemory.OverwriteOfferException
Custom exception thrown when a Player is about to offer a digit the second time before rejection or withdrawal
-
Field Summary
Fields Modifier and Type Field Description private int
_acceptanceCount
Number of acceptance messages received from Players.private boolean
_areNegotiationsFinishedPositively
Does negotiations finished positively = with a consensus?private int
_bestOffer
The offer (digit) chosen after negotiations with Players.private boolean[]
_deniedMask
Mask of forbidden digits.private boolean
_hasFinishedIteration
Flag - does this table had already finished current negotiations.private int
_iterationId
Id of current iteration.private int
_offerCount
Number of offers currently proposed by Players (offers don't have to be unique).private int[]
_offers
Values of digits offered by Players.private int[]
_requestCount
Number of requests send to a specific Player (no feedback received).private boolean[]
_specifyFlags
Flags indicating that all _weightFlags for a specific Player are set to true for all the _uniqueOffers.private ArrayList<TableOffer>
_uniqueOffers
Structure of unique offers given by Players.
-
Constructor Summary
Constructors Constructor Description TableMemory(int sudokuSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allAcceptances()
boolean
allSpecifyFlagTrue()
void
chooseBestOffer()
void
clearOffer(int n)
void
decrementRequestCount(int n)
boolean
didAlreadyFinished(int iterationId)
void
finishedIterationWithDigit(int digit)
int
getBestOffer()
int
getIterationId()
int
getOfferCount()
boolean
getSpecifyFlag(int n)
private int
getUniqueOfferIndex(int digit)
Get index of a specific offer in _uniqueOffers based on a given digit.int[]
getUnknownDigits(int n)
void
incrementAcceptanceCount()
void
incrementRequestCount(int n)
boolean
isDenied(int digit)
boolean
noRequestsPending()
void
reset()
void
resetAcceptanceCount()
void
setBestOffer(int digit)
void
setOffer(int n, int digit, float weight)
void
setSpecifyFlag(int n, boolean value)
void
setWeight(int n, int digit, float weight)
Set weight for an offer with specified digit for a single Player.private float
sumWeights(TableOffer o)
ArrayList<Integer>
withdrawDigit(int digit)
Withdraw all offers with a digit that causes conflict for some player.
-
-
-
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.
-
-
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 mappingdigit
- digit of the offerweight
- 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()
-
-