Package org.jacop.jasat.core.clauses
Class DatabasesStore
- java.lang.Object
-
- org.jacop.jasat.core.clauses.DatabasesStore
-
- All Implemented Interfaces:
ClauseDatabaseInterface,SolverComponent
public final class DatabasesStore extends java.lang.Object implements SolverComponent, ClauseDatabaseInterface
This provides a unique interface to several databases. It also translates clauses ids to get them unique across the whole system. Databases have access to it, so that they can translate unique clauses ids in both way.- Version:
- 4.8
-
-
Field Summary
Fields Modifier and Type Field Description CorecoreintcurrentIndexAbstractClausesDatabase[]databasesprivate intDATABASES_MASKprivate intINDEX_MASKprivate intINDEX_MASK_NUM_BITSprivate intLOG_OF_NUM_DATABASESprivate intMAX_NUMBER_OF_DATABASES
-
Constructor Summary
Constructors Constructor Description DatabasesStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddClause(int[] clause, boolean isModelClause)It adds a clause to the database.voidaddDatabase(AbstractClausesDatabase database)Adds a ClausesDatabase to the StorevoidassertLiteral(int literal)tells all databases that the literal is set, for unit propagation.voidbackjump(int level)tells all databases to backjump at this levelbooleancanRemove(int clauseId)It tells if the implementation of ClausesDatabase can remove clauses or notintindexesToUniqueId(int clauseIndex, int databaseIndex)It gets a unique id from a clause index, relative to a database, and a database index.voidinitialize(Core core)initializes the component with the given solver.private voidinitializeMasks()voidremoveClause(int clauseId)removes this clause from the database it belongs to.MapClauseresolutionWith(int clauseId, MapClause clause)It returns the clause obtained by resolution between clauseIndex and clause.intsize()the number of clauses in all databasesvoidtoCNF(java.io.BufferedWriter output)It writes the clauses of the databases in cnf format to the specified writer.java.lang.StringtoString()intuniqueIdToDb(int clauseId)returns the ClausesDatabase associated with this clauseIdintuniqueIdToIndex(int clauseId)Removes the database index of the clause, to get a real clause index.
-
-
-
Field Detail
-
MAX_NUMBER_OF_DATABASES
private int MAX_NUMBER_OF_DATABASES
-
DATABASES_MASK
private int DATABASES_MASK
-
INDEX_MASK
private int INDEX_MASK
-
INDEX_MASK_NUM_BITS
private int INDEX_MASK_NUM_BITS
-
LOG_OF_NUM_DATABASES
private int LOG_OF_NUM_DATABASES
-
databases
public AbstractClausesDatabase[] databases
-
currentIndex
public int currentIndex
-
core
public Core core
-
-
Method Detail
-
initializeMasks
private void initializeMasks()
-
addClause
public int addClause(int[] clause, boolean isModelClause)Description copied from interface:ClauseDatabaseInterfaceIt adds a clause to the database. This can change the state of the solver, for example if the clause is unsatisfiable in the current trail affectation, the solver will get in the conflict state.- Specified by:
addClausein interfaceClauseDatabaseInterface- Parameters:
clause- the clause to addisModelClause- defined if the clause is model clause- Returns:
- the unique ID referring to the clause
-
canRemove
public boolean canRemove(int clauseId)
Description copied from interface:ClauseDatabaseInterfaceIt tells if the implementation of ClausesDatabase can remove clauses or not- Specified by:
canRemovein interfaceClauseDatabaseInterface- Parameters:
clauseId- the unique Id of the clause- Returns:
- true iff removal of clauses is possible
-
removeClause
public void removeClause(int clauseId)
removes this clause from the database it belongs to.- Specified by:
removeClausein interfaceClauseDatabaseInterface- Parameters:
clauseId- the id of the clause to be deleted
-
resolutionWith
public MapClause resolutionWith(int clauseId, MapClause clause)
Description copied from interface:ClauseDatabaseInterfaceIt returns the clause obtained by resolution between clauseIndex and clause. It will also modify in place the given SetClause (avoid allocating).- Specified by:
resolutionWithin interfaceClauseDatabaseInterface- Parameters:
clauseId- the unique id of the clauseclause- an explanation clause that is modified by resolution- Returns:
- the clause obtained by resolution
-
addDatabase
public void addDatabase(AbstractClausesDatabase database)
Adds a ClausesDatabase to the Store- Parameters:
database- the database to add
-
size
public int size()
the number of clauses in all databases- Specified by:
sizein interfaceClauseDatabaseInterface- Returns:
- the number of clauses in the database
-
backjump
public void backjump(int level)
tells all databases to backjump at this level- Specified by:
backjumpin interfaceClauseDatabaseInterface- Parameters:
level- the level to backjump to
-
assertLiteral
public final void assertLiteral(int literal)
tells all databases that the literal is set, for unit propagation. Stops when all databases are informed, or the solver has reached a stop-state- Specified by:
assertLiteralin interfaceClauseDatabaseInterface- Parameters:
literal- the literal
-
uniqueIdToDb
public final int uniqueIdToDb(int clauseId)
returns the ClausesDatabase associated with this clauseId- Parameters:
clauseId- a unique clause Id- Returns:
- the index of the ClausesDatabase that contains the clause
-
uniqueIdToIndex
public final int uniqueIdToIndex(int clauseId)
Removes the database index of the clause, to get a real clause index. The normal way to use it is together with getClausesDatabase(), so that we have both the good database and the real id of the clause- Parameters:
clauseId- the unique clauseId- Returns:
- the clause index in the database
-
indexesToUniqueId
public final int indexesToUniqueId(int clauseIndex, int databaseIndex)It gets a unique id from a clause index, relative to a database, and a database index.- Parameters:
clauseIndex- clause indexdatabaseIndex- database index- Returns:
- unique id from a clause index
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
initialize
public void initialize(Core core)
Description copied from interface:SolverComponentinitializes the component with the given solver. May be called only once. This method must register the component to the solver for the run.- Specified by:
initializein interfaceSolverComponent- Parameters:
core- core component to initialize
-
toCNF
public void toCNF(java.io.BufferedWriter output) throws java.io.IOExceptionDescription copied from interface:ClauseDatabaseInterfaceIt writes the clauses of the databases in cnf format to the specified writer.- Specified by:
toCNFin interfaceClauseDatabaseInterface- Parameters:
output- the output writer to which all the clauses will be written to.- Throws:
java.io.IOException- execption from java.io package
-
-