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 classTableMemory.OverwriteOfferExceptionCustom 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_acceptanceCountNumber of acceptance messages received from Players.private boolean_areNegotiationsFinishedPositivelyDoes negotiations finished positively = with a consensus?private int_bestOfferThe offer (digit) chosen after negotiations with Players.private boolean[]_deniedMaskMask of forbidden digits.private boolean_hasFinishedIterationFlag - does this table had already finished current negotiations.private int_iterationIdId of current iteration.private int_offerCountNumber of offers currently proposed by Players (offers don't have to be unique).private int[]_offersValues of digits offered by Players.private int[]_requestCountNumber of requests send to a specific Player (no feedback received).private boolean[]_specifyFlagsFlags indicating that all _weightFlags for a specific Player are set to true for all the _uniqueOffers.private ArrayList<TableOffer>_uniqueOffersStructure 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 booleanallAcceptances()booleanallSpecifyFlagTrue()voidchooseBestOffer()voidclearOffer(int n)voiddecrementRequestCount(int n)booleandidAlreadyFinished(int iterationId)voidfinishedIterationWithDigit(int digit)intgetBestOffer()intgetIterationId()intgetOfferCount()booleangetSpecifyFlag(int n)private intgetUniqueOfferIndex(int digit)Get index of a specific offer in _uniqueOffers based on a given digit.int[]getUnknownDigits(int n)voidincrementAcceptanceCount()voidincrementRequestCount(int n)booleanisDenied(int digit)booleannoRequestsPending()voidreset()voidresetAcceptanceCount()voidsetBestOffer(int digit)voidsetOffer(int n, int digit, float weight)voidsetSpecifyFlag(int n, boolean value)voidsetWeight(int n, int digit, float weight)Set weight for an offer with specified digit for a single Player.private floatsumWeights(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()
-
-