idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
7,400
public < T > T apply ( final FormulaFunction < T > function , final boolean cache ) { return function . apply ( this , cache ) ; }
Applies a given function on this formula and returns the result .
7,401
public Tristate predicateCacheEntry ( final CacheEntry key ) { final Tristate tristate = this . predicateCache . get ( key ) ; if ( tristate == null ) { return Tristate . UNDEF ; } return tristate ; }
Returns an entry of the predicate cache of this formula .
7,402
public void setPredicateCacheEntry ( final CacheEntry key , final boolean value ) { this . predicateCache . put ( key , Tristate . fromBool ( value ) ) ; }
Sets an entry in the predicate cache of this formula
7,403
static Tristate evaluateCoeffs ( final int minValue , final int maxValue , final int rhs , final CType comparator ) { int status = 0 ; if ( rhs >= minValue ) status ++ ; if ( rhs > minValue ) status ++ ; if ( rhs >= maxValue ) status ++ ; if ( rhs > maxValue ) status ++ ; switch ( comparator ) { case EQ : return ( status == 0 || status == 4 ) ? Tristate . FALSE : Tristate . UNDEF ; case LE : return status >= 3 ? Tristate . TRUE : ( status < 1 ? Tristate . FALSE : Tristate . UNDEF ) ; case LT : return status > 3 ? Tristate . TRUE : ( status <= 1 ? Tristate . FALSE : Tristate . UNDEF ) ; case GE : return status <= 1 ? Tristate . TRUE : ( status > 3 ? Tristate . FALSE : Tristate . UNDEF ) ; case GT : return status < 1 ? Tristate . TRUE : ( status >= 3 ? Tristate . FALSE : Tristate . UNDEF ) ; default : throw new IllegalStateException ( "Unknown pseudo-Boolean comparator" ) ; } }
Internal helper for checking if a given coefficient - sum min - and max - value can comply with a given right - hand - side according to this PBConstraint s comparator .
7,404
public Formula normalize ( ) { final LNGVector < Literal > normPs = new LNGVector < > ( this . literals . length ) ; final LNGIntVector normCs = new LNGIntVector ( this . literals . length ) ; int normRhs ; switch ( this . comparator ) { case EQ : for ( int i = 0 ; i < this . literals . length ; i ++ ) { normPs . push ( this . literals [ i ] ) ; normCs . push ( this . coefficients [ i ] ) ; } normRhs = this . rhs ; final Formula f1 = this . normalize ( normPs , normCs , normRhs ) ; normPs . clear ( ) ; normCs . clear ( ) ; for ( int i = 0 ; i < this . literals . length ; i ++ ) { normPs . push ( this . literals [ i ] ) ; normCs . push ( - this . coefficients [ i ] ) ; } normRhs = - this . rhs ; final Formula f2 = this . normalize ( normPs , normCs , normRhs ) ; return this . f . and ( f1 , f2 ) ; case LT : case LE : for ( int i = 0 ; i < this . literals . length ; i ++ ) { normPs . push ( this . literals [ i ] ) ; normCs . push ( this . coefficients [ i ] ) ; } normRhs = this . comparator == CType . LE ? this . rhs : this . rhs - 1 ; return this . normalize ( normPs , normCs , normRhs ) ; case GT : case GE : for ( int i = 0 ; i < this . literals . length ; i ++ ) { normPs . push ( this . literals [ i ] ) ; normCs . push ( - this . coefficients [ i ] ) ; } normRhs = this . comparator == CType . GE ? - this . rhs : - this . rhs - 1 ; return this . normalize ( normPs , normCs , normRhs ) ; default : throw new IllegalStateException ( "Unknown pseudo-Boolean comparator: " + this . comparator ) ; } }
Normalizes this constraint s . t . it can be converted to CNF .
7,405
private int evaluateLHS ( final Assignment assignment ) { int lhs = 0 ; for ( int i = 0 ; i < this . literals . length ; i ++ ) if ( this . literals [ i ] . evaluate ( assignment ) ) lhs += this . coefficients [ i ] ; return lhs ; }
Returns the evaluation of the left - hand side of this constraint .
7,406
private boolean evaluateComparator ( final int lhs ) { switch ( this . comparator ) { case EQ : return lhs == this . rhs ; case LE : return lhs <= this . rhs ; case LT : return lhs < this . rhs ; case GE : return lhs >= this . rhs ; case GT : return lhs > this . rhs ; default : throw new IllegalStateException ( "Unknown pseudo-Boolean comparator" ) ; } }
Computes the result of evaluating the comparator with a given left - hand side .
7,407
public static < T > void write ( final String fileName , Graph < T > g , boolean writeMapping ) throws IOException { File file = new File ( fileName . endsWith ( ".col" ) ? fileName : fileName + ".col" ) ; Map < Node < T > , Long > node2id = new LinkedHashMap < > ( ) ; long i = 1 ; for ( Node < T > node : g . nodes ( ) ) { node2id . put ( node , i ++ ) ; } StringBuilder sb = new StringBuilder ( "p edge " ) ; Set < Pair < Node < T > , Node < T > > > edges = new LinkedHashSet < > ( ) ; Set < Node < T > > doneNodes = new LinkedHashSet < > ( ) ; for ( Node < T > d : g . nodes ( ) ) { for ( Node < T > n : d . neighbours ( ) ) { if ( ! doneNodes . contains ( n ) ) { edges . add ( new Pair < > ( d , n ) ) ; } } doneNodes . add ( d ) ; } sb . append ( node2id . size ( ) ) . append ( " " ) . append ( edges . size ( ) ) . append ( System . lineSeparator ( ) ) ; for ( Pair < Node < T > , Node < T > > edge : edges ) { sb . append ( "e " ) . append ( node2id . get ( edge . first ( ) ) ) . append ( " " ) . append ( node2id . get ( edge . second ( ) ) ) . append ( System . lineSeparator ( ) ) ; } try ( BufferedWriter writer = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( file ) , StandardCharsets . UTF_8 ) ) ) { writer . append ( sb ) ; writer . flush ( ) ; } if ( writeMapping ) { String mappingFileName = ( fileName . endsWith ( ".col" ) ? fileName . substring ( 0 , fileName . length ( ) - 4 ) : fileName ) + ".map" ; writeMapping ( new File ( mappingFileName ) , node2id ) ; } }
Writes a given graph s internal data structure as a dimacs file .
7,408
public static CleaneLing minimalistic ( final FormulaFactory f ) { return new CleaneLing ( f , SolverStyle . MINIMALISTIC , new CleaneLingConfig . Builder ( ) . build ( ) ) ; }
Returns a new minimalistic CleaneLing solver .
7,409
public static CleaneLing minimalistic ( final FormulaFactory f , final CleaneLingConfig config ) { return new CleaneLing ( f , SolverStyle . MINIMALISTIC , config ) ; }
Returns a new minimalistic CleaneLing solver with a given configuration .
7,410
public static CleaneLing full ( final FormulaFactory f ) { return new CleaneLing ( f , SolverStyle . FULL , new CleaneLingConfig . Builder ( ) . build ( ) ) ; }
Returns a new full CleaneLing solver .
7,411
public static CleaneLing full ( final FormulaFactory f , final CleaneLingConfig config ) { return new CleaneLing ( f , SolverStyle . FULL , config ) ; }
Returns a new full CleaneLing solver with a given configuration .
7,412
private void addClause ( final Collection < Literal > literals ) { for ( final Literal lit : literals ) { Integer index = this . name2idx . get ( lit . variable ( ) . name ( ) ) ; if ( index == null ) { index = this . name2idx . size ( ) + 1 ; this . name2idx . put ( lit . variable ( ) . name ( ) , index ) ; this . idx2name . put ( index , lit . variable ( ) . name ( ) ) ; } this . solver . addlit ( lit . phase ( ) ? index : - index ) ; } this . solver . addlit ( CLAUSE_TERMINATOR ) ; }
Adds a collection of literals to the solver .
7,413
public int getOrCreateVarIndex ( final Variable var ) { Integer index = this . name2idx . get ( var . name ( ) ) ; if ( index == null ) { index = this . name2idx . size ( ) + 1 ; this . name2idx . put ( var . name ( ) , index ) ; this . idx2name . put ( index , var . name ( ) ) ; } return index ; }
Returns the existing internal solver index for a variable or creates a new one if the variable is yet unknown .
7,414
public String createNewVariableOnSolver ( final String prefix ) { final int index = this . name2idx . size ( ) + 1 ; final String varName = prefix + "_" + index ; this . name2idx . put ( varName , index ) ; this . idx2name . put ( index , varName ) ; return varName ; }
Creates a new variable on the solver and returns its name .
7,415
private LinkedHashSet < Formula > gatherAppliedOperands ( final NAryOperator operator ) { final LinkedHashSet < Formula > applied = new LinkedHashSet < > ( ) ; for ( final Formula operand : operator ) { applied . add ( apply ( operand , false ) ) ; } return applied ; }
Gather the operands of an n - ary operator and returns its applied operands .
7,416
public void setNumberOfVars ( final int num ) { if ( this . varnum != 0 ) throw new UnsupportedOperationException ( "Variable number is already set. Resetting it is not supported" ) ; if ( num < 1 || num > MAXVAR ) throw new IllegalArgumentException ( "Invalid variable number: " + num ) ; this . vars = new int [ num * 2 ] ; this . level2var = new int [ num + 1 ] ; this . refstack = new int [ num * 2 + 4 ] ; this . refstacktop = 0 ; while ( this . varnum < num ) { this . vars [ this . varnum * 2 ] = pushRef ( makeNode ( this . varnum , 0 , 1 ) ) ; this . vars [ this . varnum * 2 + 1 ] = makeNode ( this . varnum , 1 , 0 ) ; popref ( 1 ) ; this . nodes [ this . vars [ this . varnum * 2 ] ] . refcou = MAXREF ; this . nodes [ this . vars [ this . varnum * 2 + 1 ] ] . refcou = MAXREF ; this . level2var [ this . varnum ] = this . varnum ; this . varnum ++ ; } this . nodes [ 0 ] . level = num ; this . nodes [ 1 ] . level = num ; this . level2var [ num ] = num ; varResize ( ) ; }
Sets the number of variables to use . It may be called more than one time but only to increase the number of variables .
7,417
private void delRef ( final int root ) { if ( root < 2 ) return ; if ( root >= this . nodesize ) throw new IllegalStateException ( "Cannot dereference a variable > varnum" ) ; if ( this . low ( root ) == - 1 ) throw new IllegalStateException ( "Cannot dereference variable -1" ) ; if ( ! this . hasref ( root ) ) throw new IllegalStateException ( "Cannot dereference a variable which has no reference" ) ; this . decRef ( root ) ; }
Deletes a reference for a given node .
7,418
public List < byte [ ] > allSat ( final int r ) { final byte [ ] allsatProfile = new byte [ this . varnum ] ; for ( int v = level ( r ) - 1 ; v >= 0 ; -- v ) allsatProfile [ this . level2var [ v ] ] = - 1 ; initRef ( ) ; final List < byte [ ] > allSat = new LinkedList < > ( ) ; allSatRec ( r , allSat , allsatProfile ) ; return allSat ; }
Returns all models for a given BDD .
7,419
private void initializeGlucose ( ) { this . initializeGlucoseConfig ( ) ; this . watchesBin = new LNGVector < > ( ) ; this . permDiff = new LNGIntVector ( ) ; this . lastDecisionLevel = new LNGIntVector ( ) ; this . lbdQueue = new LNGBoundedLongQueue ( ) ; this . trailQueue = new LNGBoundedIntQueue ( ) ; this . assump = new LNGBooleanVector ( ) ; this . lbdQueue . initSize ( sizeLBDQueue ) ; this . trailQueue . initSize ( sizeTrailQueue ) ; this . myflag = 0 ; this . analyzeBtLevel = 0 ; this . analyzeLBD = 0 ; this . analyzeSzWithoutSelectors = 0 ; this . nbclausesbeforereduce = firstReduceDB ; this . conflicts = 0 ; this . conflictsRestarts = 0 ; this . sumLBD = 0 ; this . curRestart = 1 ; }
Initializes the additional parameters .
7,420
private void initializeGlucoseConfig ( ) { this . lbLBDMinimizingClause = glucoseConfig . lbLBDMinimizingClause ; this . lbLBDFrozenClause = glucoseConfig . lbLBDFrozenClause ; this . lbSizeMinimizingClause = glucoseConfig . lbSizeMinimizingClause ; this . firstReduceDB = glucoseConfig . firstReduceDB ; this . specialIncReduceDB = glucoseConfig . specialIncReduceDB ; this . incReduceDB = glucoseConfig . incReduceDB ; this . factorK = glucoseConfig . factorK ; this . factorR = glucoseConfig . factorR ; this . sizeLBDQueue = glucoseConfig . sizeLBDQueue ; this . sizeTrailQueue = glucoseConfig . sizeTrailQueue ; this . reduceOnSize = glucoseConfig . reduceOnSize ; this . reduceOnSizeSize = glucoseConfig . reduceOnSizeSize ; this . maxVarDecay = glucoseConfig . maxVarDecay ; }
Initializes the glucose configuration .
7,421
private long computeLBD ( final LNGIntVector lits , int e ) { int end = e ; long nblevels = 0 ; myflag ++ ; if ( incremental ) { if ( end == - 1 ) end = lits . size ( ) ; long nbDone = 0 ; for ( int i = 0 ; i < lits . size ( ) ; i ++ ) { if ( nbDone >= end ) break ; if ( isSelector ( var ( lits . get ( i ) ) ) ) continue ; nbDone ++ ; int l = v ( lits . get ( i ) ) . level ( ) ; if ( permDiff . get ( l ) != myflag ) { permDiff . set ( l , myflag ) ; nblevels ++ ; } } } else { for ( int i = 0 ; i < lits . size ( ) ; i ++ ) { int l = v ( lits . get ( i ) ) . level ( ) ; if ( permDiff . get ( l ) != myflag ) { permDiff . set ( l , myflag ) ; nblevels ++ ; } } } if ( ! reduceOnSize ) return nblevels ; if ( lits . size ( ) < reduceOnSizeSize ) return lits . size ( ) ; return lits . size ( ) + nblevels ; }
Computes the LBD for a given vector of literals .
7,422
private long computeLBD ( final MSClause c ) { long nblevels = 0 ; myflag ++ ; if ( incremental ) { long nbDone = 0 ; for ( int i = 0 ; i < c . size ( ) ; i ++ ) { if ( nbDone >= c . sizeWithoutSelectors ( ) ) break ; if ( isSelector ( var ( c . get ( i ) ) ) ) continue ; nbDone ++ ; int l = v ( c . get ( i ) ) . level ( ) ; if ( permDiff . get ( l ) != myflag ) { permDiff . set ( l , myflag ) ; nblevels ++ ; } } } else { for ( int i = 0 ; i < c . size ( ) ; i ++ ) { int l = v ( c . get ( i ) ) . level ( ) ; if ( permDiff . get ( l ) != myflag ) { permDiff . set ( l , myflag ) ; nblevels ++ ; } } } if ( ! reduceOnSize ) return nblevels ; if ( c . size ( ) < reduceOnSizeSize ) return c . size ( ) ; return c . size ( ) + nblevels ; }
Computes the LBD for a given clause
7,423
private void minimisationWithBinaryResolution ( final LNGIntVector outLearnt ) { long lbd = computeLBD ( outLearnt , - 1 ) ; int p = not ( outLearnt . get ( 0 ) ) ; if ( lbd <= lbLBDMinimizingClause ) { myflag ++ ; for ( int i = 1 ; i < outLearnt . size ( ) ; i ++ ) permDiff . set ( var ( outLearnt . get ( i ) ) , myflag ) ; int nb = 0 ; for ( final MSWatcher wbin : watchesBin . get ( p ) ) { int imp = wbin . blocker ( ) ; if ( permDiff . get ( var ( imp ) ) == myflag && value ( imp ) == Tristate . TRUE ) { nb ++ ; permDiff . set ( var ( imp ) , myflag - 1 ) ; } } int l = outLearnt . size ( ) - 1 ; if ( nb > 0 ) { for ( int i = 1 ; i < outLearnt . size ( ) - nb ; i ++ ) { if ( permDiff . get ( var ( outLearnt . get ( i ) ) ) != myflag ) { p = outLearnt . get ( l ) ; outLearnt . set ( l , outLearnt . get ( i ) ) ; outLearnt . set ( i , p ) ; l -- ; i -- ; } } outLearnt . removeElements ( nb ) ; } } }
A special clause minimization by binary resolution for small clauses .
7,424
private int buildRec ( final Formula formula ) { switch ( formula . type ( ) ) { case FALSE : return BDDKernel . BDD_FALSE ; case TRUE : return BDDKernel . BDD_TRUE ; case LITERAL : final Literal lit = ( Literal ) formula ; Integer idx = this . var2idx . get ( lit . variable ( ) ) ; if ( idx == null ) { idx = this . var2idx . size ( ) ; this . var2idx . put ( lit . variable ( ) , idx ) ; this . idx2var . put ( idx , lit . variable ( ) ) ; } return lit . phase ( ) ? this . kernel . ithVar ( idx ) : this . kernel . nithVar ( idx ) ; case NOT : final Not not = ( Not ) formula ; return this . kernel . addRef ( this . kernel . not ( buildRec ( not . operand ( ) ) ) ) ; case IMPL : final Implication impl = ( Implication ) formula ; return this . kernel . addRef ( this . kernel . implication ( buildRec ( impl . left ( ) ) , buildRec ( impl . right ( ) ) ) ) ; case EQUIV : final Equivalence equiv = ( Equivalence ) formula ; return this . kernel . addRef ( this . kernel . equivalence ( buildRec ( equiv . left ( ) ) , buildRec ( equiv . right ( ) ) ) ) ; case AND : case OR : final Iterator < Formula > it = formula . iterator ( ) ; int res = buildRec ( it . next ( ) ) ; while ( it . hasNext ( ) ) res = formula . type ( ) == AND ? this . kernel . addRef ( this . kernel . and ( res , buildRec ( it . next ( ) ) ) ) : this . kernel . addRef ( this . kernel . or ( res , buildRec ( it . next ( ) ) ) ) ; return res ; case PBC : return buildRec ( formula . nnf ( ) ) ; default : throw new IllegalArgumentException ( "Unsupported operator for BDD generation: " + formula . type ( ) ) ; } }
Recursive build procedure for the BDD .
7,425
public void setVariableOrder ( final Variable ... varOrder ) { this . kernel . setNumberOfVars ( varOrder . length ) ; for ( final Variable lit : varOrder ) { final int idx = this . var2idx . size ( ) ; this . var2idx . put ( lit . variable ( ) , idx ) ; this . idx2var . put ( idx , lit . variable ( ) ) ; } }
Sets the variable order for this factory manually . In this case the number of variables has not to be set manually .
7,426
public BigDecimal modelCount ( final BDD bdd , final int unimportantVars ) { return modelCount ( bdd ) . divide ( BigDecimal . valueOf ( ( int ) Math . pow ( 2 , unimportantVars ) ) ) ; }
Returns the model count of a given BDD with a given number of unimportant variables .
7,427
public List < Assignment > enumerateAllModels ( final BDD bdd , final Collection < Variable > variables ) { final Set < Assignment > res = new HashSet < > ( ) ; final List < byte [ ] > models = this . kernel . allSat ( bdd . index ( ) ) ; final SortedSet < Integer > temp ; if ( variables == null ) temp = new TreeSet < > ( this . var2idx . values ( ) ) ; else { temp = new TreeSet < > ( ) ; for ( final Map . Entry < Variable , Integer > e : this . var2idx . entrySet ( ) ) if ( variables . contains ( e . getKey ( ) ) ) temp . add ( e . getValue ( ) ) ; } final int [ ] relevantIndices = new int [ temp . size ( ) ] ; int count = 0 ; for ( final Integer i : temp ) relevantIndices [ count ++ ] = i ; for ( final byte [ ] model : models ) { final List < Assignment > allAssignments = new LinkedList < > ( ) ; generateAllModels ( allAssignments , model , relevantIndices , 0 ) ; res . addAll ( allAssignments ) ; } return new ArrayList < > ( res ) ; }
Enumerates all models of a given BDD wrt . a given set of variables .
7,428
public Formula cnf ( final BDD bdd ) { final List < byte [ ] > unsatPaths = this . kernel . allUnsat ( bdd . index ( ) ) ; final List < Formula > clauses = new LinkedList < > ( ) ; List < Formula > literals ; for ( final byte [ ] path : unsatPaths ) { literals = new LinkedList < > ( ) ; for ( int i = 0 ; i < path . length ; i ++ ) if ( path [ i ] == 0 ) literals . add ( this . idx2var . get ( i ) ) ; else if ( path [ i ] == 1 ) literals . add ( this . idx2var . get ( i ) . negate ( ) ) ; clauses . add ( this . f . or ( literals ) ) ; } return this . f . and ( clauses ) ; }
Returns a CNF formula for a given BDD .
7,429
public Formula dnf ( final BDD bdd ) { final List < Formula > ops = new LinkedList < > ( ) ; for ( final Assignment ass : this . enumerateAllModels ( bdd ) ) ops . add ( ass . formula ( this . f ) ) ; return ops . isEmpty ( ) ? this . f . falsum ( ) : this . f . or ( ops ) ; }
Returns a DNF formula for a given BDD .
7,430
public SortedSet < Variable > support ( final BDD bdd ) { final int supportBDD = this . kernel . support ( bdd . index ( ) ) ; final Assignment assignment = createAssignment ( supportBDD ) ; assert assignment == null || assignment . negativeLiterals ( ) . isEmpty ( ) ; return assignment == null ? new TreeSet < Variable > ( ) : new TreeSet < > ( assignment . positiveLiterals ( ) ) ; }
Returns all the variables that a given BDD depends on .
7,431
private Assignment createAssignment ( final int modelBDD ) { if ( modelBDD == BDDKernel . BDD_FALSE ) return null ; if ( modelBDD == BDDKernel . BDD_TRUE ) return new Assignment ( ) ; final List < int [ ] > nodes = this . kernel . allNodes ( modelBDD ) ; final Assignment assignment = new Assignment ( ) ; for ( final int [ ] node : nodes ) { final Variable variable = this . idx2var . get ( node [ 1 ] ) ; if ( node [ 2 ] == BDDKernel . BDD_FALSE ) assignment . addLiteral ( variable ) ; else if ( node [ 3 ] == BDDKernel . BDD_FALSE ) assignment . addLiteral ( variable . negate ( ) ) ; else throw new IllegalStateException ( "Expected that the model BDD has one unique path through the BDD." ) ; } return assignment ; }
Creates an assignment from a BDD .
7,432
public SortedMap < Variable , Integer > variableProfile ( final BDD bdd ) { final int [ ] varProfile = this . kernel . varProfile ( bdd . index ( ) ) ; final SortedMap < Variable , Integer > profile = new TreeMap < > ( ) ; for ( int i = 0 ; i < varProfile . length ; i ++ ) { profile . put ( this . idx2var . get ( i ) , varProfile [ i ] ) ; } return profile ; }
Returns how often each variable occurs in the given BDD .
7,433
public BDDNode toLngBdd ( final int bdd ) { final BDDConstant falseNode = BDDConstant . getFalsumNode ( this . f ) ; final BDDConstant trueNode = BDDConstant . getVerumNode ( this . f ) ; if ( bdd == BDDKernel . BDD_FALSE ) return falseNode ; if ( bdd == BDDKernel . BDD_TRUE ) return trueNode ; final List < int [ ] > nodes = this . kernel . allNodes ( bdd ) ; final Map < Integer , BDDInnerNode > innerNodes = new HashMap < > ( ) ; for ( final int [ ] node : nodes ) { final int nodenum = node [ 0 ] ; final Variable variable = this . idx2var . get ( node [ 1 ] ) ; final BDDNode lowNode = getInnerNode ( node [ 2 ] , falseNode , trueNode , innerNodes ) ; final BDDNode highNode = getInnerNode ( node [ 3 ] , falseNode , trueNode , innerNodes ) ; if ( innerNodes . get ( nodenum ) == null ) innerNodes . put ( nodenum , new BDDInnerNode ( variable , lowNode , highNode ) ) ; } return innerNodes . get ( bdd ) ; }
Returns a LogicNG internal BDD data structure of a given BDD .
7,434
public Formula formula ( final FormulaFactory f ) { if ( this . operator != FType . AND && this . operator != FType . OR ) throw new IllegalStateException ( "Illegal operator for formula list formula construction: " + this . operator ) ; if ( this . formula == null ) { if ( this . operator == FType . AND ) this . formula = f . and ( this . formulas ) ; else this . formula = f . or ( this . formulas ) ; } return this . formula ; }
Returns this formula list as a formula if there is an operator .
7,435
public Formula get ( final int i ) { if ( i < 0 || i >= this . formulas . length ) throw new IllegalArgumentException ( "Illegal formula index: " + i ) ; return this . formulas [ i ] ; }
Returns the i - th formula of this formula list .
7,436
public SortedSet < Variable > variables ( ) { if ( this . variables == null ) { this . variables = new TreeSet < > ( ) ; for ( final Formula f : this . formulas ) this . variables . addAll ( f . variables ( ) ) ; } return this . variables ; }
Returns all variables occurring in this formula list .
7,437
public SortedSet < Literal > getCompleteBackbone ( ) { final SortedSet < Literal > completeBackbone = new TreeSet < > ( ) ; if ( hasPositiveBackboneResult ( ) ) { completeBackbone . addAll ( this . positiveBackbone ) ; } if ( hasNegativeBackboneResult ( ) ) { for ( final Variable var : this . negativeBackbone ) { completeBackbone . add ( var . negate ( ) ) ; } } return Collections . unmodifiableSortedSet ( completeBackbone ) ; }
Returns all literals of the backbone . Positive backbone variables have positive polarity negative backbone variables have negative polarity .
7,438
public Node < T > node ( T content ) { final Node < T > search = nodes . get ( content ) ; if ( search != null ) return search ; final Node < T > n = new Node < > ( content , this ) ; nodes . put ( content , n ) ; return n ; }
Returns the node with a given content . If such a node does not exist it is created and added to the graph .
7,439
public void encodeAMO ( final MiniSatStyleSolver s , final LNGIntVector lits ) { switch ( this . amoEncoding ) { case LADDER : this . ladder . encode ( s , lits ) ; break ; default : throw new IllegalStateException ( "Unknown AMO encoding: " + this . amoEncoding ) ; } }
Encodes an AMO constraint in the given solver .
7,440
public void encodeCardinality ( final MiniSatStyleSolver s , final LNGIntVector lits , int rhs ) { switch ( this . cardinalityEncoding ) { case TOTALIZER : this . totalizer . build ( s , lits , rhs ) ; if ( this . totalizer . hasCreatedEncoding ( ) ) this . totalizer . update ( s , rhs ) ; break ; case MTOTALIZER : this . mtotalizer . encode ( s , lits , rhs ) ; break ; default : throw new IllegalStateException ( "Unknown cardinality encoding: " + this . cardinalityEncoding ) ; } }
Encodes a cardinality constraint in the given solver .
7,441
public void updateCardinality ( final MiniSatStyleSolver s , int rhs ) { switch ( this . cardinalityEncoding ) { case TOTALIZER : this . totalizer . update ( s , rhs ) ; break ; case MTOTALIZER : this . mtotalizer . update ( s , rhs ) ; break ; default : throw new IllegalStateException ( "Unknown cardinality encoding: " + this . cardinalityEncoding ) ; } }
Updates the cardinality constraint .
7,442
public void buildCardinality ( final MiniSatStyleSolver s , final LNGIntVector lits , int rhs ) { assert this . incrementalStrategy != IncrementalStrategy . NONE ; switch ( this . cardinalityEncoding ) { case TOTALIZER : this . totalizer . build ( s , lits , rhs ) ; break ; default : throw new IllegalStateException ( "Cardinality encoding does not support incrementality: " + this . incrementalStrategy ) ; } }
Manages the building of cardinality encodings . Currently is only used for incremental solving .
7,443
public void incUpdateCardinality ( final MiniSatStyleSolver s , final LNGIntVector join , final LNGIntVector lits , int rhs , final LNGIntVector assumptions ) { assert this . incrementalStrategy == IncrementalStrategy . ITERATIVE ; switch ( this . cardinalityEncoding ) { case TOTALIZER : if ( join . size ( ) > 0 ) this . totalizer . join ( s , join , rhs ) ; assert lits . size ( ) > 0 ; this . totalizer . update ( s , rhs , assumptions ) ; break ; default : throw new IllegalArgumentException ( "Cardinality encoding does not support incrementality: " + this . incrementalStrategy ) ; } }
Manages the incremental update of cardinality constraints .
7,444
public void encodePB ( final MiniSatStyleSolver s , final LNGIntVector lits , final LNGIntVector coeffs , int rhs ) { switch ( this . pbEncoding ) { case SWC : this . swc . encode ( s , lits , coeffs , rhs ) ; break ; default : throw new IllegalStateException ( "Unknown pseudo-Boolean encoding: " + this . pbEncoding ) ; } }
Encodes a pseudo - Boolean constraint .
7,445
public void updatePB ( final MiniSatStyleSolver s , int rhs ) { switch ( this . pbEncoding ) { case SWC : this . swc . update ( s , rhs ) ; break ; default : throw new IllegalStateException ( "Unknown pseudo-Boolean encoding: " + this . pbEncoding ) ; } }
Updates a pseudo - Boolean encoding .
7,446
public void incEncodePB ( final MiniSatStyleSolver s , final LNGIntVector lits , final LNGIntVector coeffs , int rhs , final LNGIntVector assumptions , int size ) { assert this . incrementalStrategy == IncrementalStrategy . ITERATIVE ; switch ( this . pbEncoding ) { case SWC : this . swc . encode ( s , lits , coeffs , rhs , assumptions , size ) ; break ; default : throw new IllegalStateException ( "Unknown pseudo-Boolean encoding: " + this . pbEncoding ) ; } }
Incrementally encodes a pseudo - Boolean constraint .
7,447
public void incUpdatePB ( final MiniSatStyleSolver s , final LNGIntVector lits , final LNGIntVector coeffs , int rhs ) { assert this . incrementalStrategy == IncrementalStrategy . ITERATIVE ; switch ( this . pbEncoding ) { case SWC : this . swc . updateInc ( s , rhs ) ; this . swc . join ( s , lits , coeffs ) ; break ; default : throw new IllegalStateException ( "Unknown pseudo-Boolean encoding: " + this . pbEncoding ) ; } }
Manages the incremental update of pseudo - Boolean encodings .
7,448
public void incUpdatePBAssumptions ( final LNGIntVector assumptions ) { assert this . incrementalStrategy == IncrementalStrategy . ITERATIVE ; switch ( this . pbEncoding ) { case SWC : this . swc . updateAssumptions ( assumptions ) ; break ; default : throw new IllegalStateException ( "Unknown pseudo-Boolean encoding: " + this . pbEncoding ) ; } }
Manages the incremental update of assumptions .
7,449
private void growTo ( int size ) { this . elems . growTo ( size , 0 ) ; this . first = 0 ; this . maxSize = size ; this . queueSize = 0 ; this . last = 0 ; }
Grows this queue to a given size .
7,450
void setLexerAndParser ( final Lexer lexer , final ParserWithFormula parser ) { this . lexer = lexer ; this . parser = parser ; this . parser . setFormulaFactory ( this . f ) ; this . lexer . removeErrorListeners ( ) ; this . parser . removeErrorListeners ( ) ; this . parser . setErrorHandler ( new BailErrorStrategy ( ) ) ; }
Sets the internal lexer and the parser .
7,451
public Formula parse ( final InputStream inputStream ) throws ParserException { if ( inputStream == null ) { return this . f . verum ( ) ; } try { final CharStream input = CharStreams . fromStream ( inputStream ) ; this . lexer . setInputStream ( input ) ; final CommonTokenStream tokens = new CommonTokenStream ( this . lexer ) ; this . parser . setInputStream ( tokens ) ; return this . parser . getParsedFormula ( ) ; } catch ( final IOException e ) { throw new ParserException ( "IO exception when parsing the formula" , e ) ; } catch ( final ParseCancellationException e ) { throw new ParserException ( "Parse cancellation exception when parsing the formula" , e ) ; } catch ( final LexerException e ) { throw new ParserException ( "Lexer exception when parsing the formula." , e ) ; } }
Parses and returns a given input stream .
7,452
public Formula parse ( final String in ) throws ParserException { if ( in == null || in . isEmpty ( ) ) { return this . f . verum ( ) ; } try { final CharStream input = CharStreams . fromString ( in ) ; this . lexer . setInputStream ( input ) ; final CommonTokenStream tokens = new CommonTokenStream ( this . lexer ) ; this . parser . setInputStream ( tokens ) ; return this . parser . getParsedFormula ( ) ; } catch ( final ParseCancellationException e ) { throw new ParserException ( "Parse cancellation exception when parsing the formula" , e ) ; } catch ( final LexerException e ) { throw new ParserException ( "Lexer exception when parsing the formula." , e ) ; } }
Parses and returns a given string .
7,453
private void encodeNonRecursive ( final LNGVector < Literal > literals ) { if ( literals . size ( ) > 1 ) for ( int i = 0 ; i < literals . size ( ) ; i ++ ) for ( int j = i + 1 ; j < literals . size ( ) ; j ++ ) this . result . addClause ( literals . get ( i ) . negate ( ) , literals . get ( j ) . negate ( ) ) ; }
Internal non recursive encoding .
7,454
public void update ( final MiniSatStyleSolver s , int rhs ) { final LNGIntVector assumptions = new LNGIntVector ( ) ; this . update ( s , rhs , assumptions ) ; }
Updates the right hand side .
7,455
void join ( final MiniSatStyleSolver s , final LNGIntVector lits , int rhs ) { assert this . incrementalStrategy == MaxSATConfig . IncrementalStrategy . ITERATIVE ; final LNGIntVector leftCardinalityOutlits = new LNGIntVector ( this . cardinalityOutlits ) ; int oldCardinality = this . currentCardinalityRhs ; if ( lits . size ( ) > 1 ) this . build ( s , lits , rhs < lits . size ( ) ? rhs : lits . size ( ) ) ; else { assert lits . size ( ) == 1 ; this . cardinalityOutlits . clear ( ) ; this . cardinalityOutlits . push ( lits . get ( 0 ) ) ; } final LNGIntVector rightCardinalityOutlits = new LNGIntVector ( this . cardinalityOutlits ) ; this . cardinalityOutlits . clear ( ) ; for ( int i = 0 ; i < leftCardinalityOutlits . size ( ) + rightCardinalityOutlits . size ( ) ; i ++ ) { final int p = mkLit ( s . nVars ( ) , false ) ; MaxSAT . newSATVariable ( s ) ; this . cardinalityOutlits . push ( p ) ; } this . currentCardinalityRhs = rhs ; this . adder ( s , leftCardinalityOutlits , rightCardinalityOutlits , this . cardinalityOutlits ) ; this . currentCardinalityRhs = oldCardinality ; }
Joins two constraints . The given constraint is added to the current one .
7,456
public Formula encode ( final Formula formula ) { switch ( this . config ( ) . algorithm ) { case FACTORIZATION : if ( this . factorization == null ) this . factorization = new CNFFactorization ( ) ; return formula . transform ( this . factorization ) ; case TSEITIN : if ( this . tseitin == null || this . currentAtomBoundary != this . config ( ) . atomBoundary ) { this . currentAtomBoundary = this . config ( ) . atomBoundary ; this . tseitin = new TseitinTransformation ( this . config ( ) . atomBoundary ) ; } return formula . transform ( this . tseitin ) ; case PLAISTED_GREENBAUM : if ( this . plaistedGreenbaum == null || this . currentAtomBoundary != this . config ( ) . atomBoundary ) { this . currentAtomBoundary = this . config ( ) . atomBoundary ; this . plaistedGreenbaum = new PlaistedGreenbaumTransformation ( this . config ( ) . atomBoundary ) ; } return formula . transform ( this . plaistedGreenbaum ) ; case BDD : if ( this . bddCnfTransformation == null ) this . bddCnfTransformation = new BDDCNFTransformation ( ) ; return formula . transform ( this . bddCnfTransformation ) ; case ADVANCED : if ( this . factorizationHandler == null ) { this . factorizationHandler = new AdvancedFactorizationHandler ( ) ; this . advancedFactorization = new CNFFactorization ( this . factorizationHandler ) ; } this . factorizationHandler . reset ( this . config ( ) . distributionBoundary , this . config ( ) . createdClauseBoundary ) ; return this . advancedEncoding ( formula ) ; default : throw new IllegalStateException ( "Unknown CNF encoding algorithm: " + this . config ( ) . algorithm ) ; } }
Encodes a formula to CNF .
7,457
private Formula advancedEncoding ( final Formula formula ) { if ( formula . type ( ) == FType . AND ) { final List < Formula > operands = new ArrayList < > ( formula . numberOfOperands ( ) ) ; for ( final Formula op : formula ) operands . add ( singleAdvancedEncoding ( op ) ) ; return this . f . and ( operands ) ; } return singleAdvancedEncoding ( formula ) ; }
Encodes the given formula to CNF by first trying to use Factorization for the single sub - formulas . When certain user - provided boundaries are met the method is switched to Tseitin or Plaisted & Greenbaum .
7,458
private static Map < Literal , Integer > nonCachingLiteralProfile ( final Formula formula ) { final SortedMap < Literal , Integer > map = new TreeMap < > ( ) ; nonCachingRecursion ( formula , map ) ; return map ; }
The non - caching implementation of the literal profile computation . In this case the result map is only constructed once and results are just added to it .
7,459
public void printSolverState ( final PrintStream output ) { output . println ( "level=" + this . level ) ; output . println ( "next=" + this . next ) ; output . println ( "ignore=" + this . ignore ) ; output . println ( "empty=" + this . empty ) ; output . println ( "vars=" + this . vars ) ; output . println ( "vals=" + this . vals ) ; output . println ( "phases=" + this . phases ) ; output . println ( "decisions=" + this . decisions ) ; output . println ( "control=" + this . control ) ; output . println ( "watches=" + this . watches ) ; output . println ( "trail=" + this . trail ) ; output . println ( "frames=" + this . frames ) ; }
Prints the current solver state to a given output stream .
7,460
public void add ( final Formula formula ) { final Formula cnf = formula . cnf ( ) ; switch ( cnf . type ( ) ) { case TRUE : break ; case FALSE : case LITERAL : case OR : this . addClause ( generateClauseVector ( cnf ) , null ) ; break ; case AND : for ( final Formula op : cnf ) { this . addClause ( generateClauseVector ( op ) , null ) ; } break ; default : throw new IllegalStateException ( "Unexpected formula type in CNF: " + cnf . type ( ) ) ; } }
Adds an arbitrary formula to the solver .
7,461
private List < Integer > getRelevantVarIndices ( final Collection < Variable > variables ) { final List < Integer > relevantVarIndices = new ArrayList < > ( variables . size ( ) ) ; for ( final Variable var : variables ) { final Integer idx = this . name2idx . get ( var . name ( ) ) ; if ( idx != null ) { relevantVarIndices . add ( idx ) ; } } return relevantVarIndices ; }
Returns a list of relevant variable indices . A relevant variable is known by the solver .
7,462
private Backbone buildBackbone ( final Collection < Variable > variables ) { final SortedSet < Variable > posBackboneVars = isBothOrPositiveType ( ) ? new TreeSet < Variable > ( ) : null ; final SortedSet < Variable > negBackboneVars = isBothOrNegativeType ( ) ? new TreeSet < Variable > ( ) : null ; final SortedSet < Variable > optionalVars = isBothType ( ) ? new TreeSet < Variable > ( ) : null ; for ( final Variable var : variables ) { final Integer idx = this . name2idx . get ( var . name ( ) ) ; if ( idx == null ) { if ( isBothType ( ) ) { optionalVars . add ( var ) ; } } else { switch ( this . backboneMap . get ( idx ) ) { case TRUE : if ( isBothOrPositiveType ( ) ) { posBackboneVars . add ( var ) ; } break ; case FALSE : if ( isBothOrNegativeType ( ) ) { negBackboneVars . add ( var ) ; } break ; case UNDEF : if ( isBothType ( ) ) { optionalVars . add ( var ) ; } break ; default : throw new IllegalStateException ( "Unknown tristate: " + this . backboneMap . get ( idx ) ) ; } } } return new Backbone ( posBackboneVars , negBackboneVars , optionalVars ) ; }
Builds the backbone object from the computed backbone literals .
7,463
public Backbone compute ( final Collection < Variable > variables , final BackboneType type ) { final boolean sat = solve ( null ) == Tristate . TRUE ; Backbone backbone = null ; if ( sat ) { final List < Integer > relevantVarIndices = getRelevantVarIndices ( variables ) ; init ( relevantVarIndices , type ) ; compute ( relevantVarIndices ) ; backbone = buildBackbone ( variables ) ; } return backbone ; }
Computes the backbone of the given variables with respect to the formulas added to the solver .
7,464
private boolean isUnit ( final int lit , final MSClause clause ) { for ( int i = 0 ; i < clause . size ( ) ; ++ i ) { final int clauseLit = clause . get ( i ) ; if ( lit != clauseLit && this . model . get ( var ( clauseLit ) ) != sign ( clauseLit ) ) { return false ; } } return true ; }
Tests the given literal whether it is unit in the given clause .
7,465
private boolean isRotatable ( final int lit ) { if ( v ( var ( lit ) ) . reason ( ) != null ) { return false ; } for ( final MSWatcher watcher : this . watches . get ( not ( lit ) ) ) { if ( isUnit ( lit , watcher . clause ( ) ) ) { return false ; } } return true ; }
Tests the given literal whether it is rotatable in the current model .
7,466
private void addBackboneLiteral ( final int lit ) { this . backboneMap . put ( var ( lit ) , sign ( lit ) ? Tristate . FALSE : Tristate . TRUE ) ; this . assumptions . push ( lit ) ; }
Adds the given literal to the backbone result and optionally adds the literal to the solver .
7,467
private Stack < Integer > createInitialCandidates ( final List < Integer > variables ) { for ( final Integer var : variables ) { if ( isUPZeroLit ( var ) ) { final int backboneLit = mkLit ( var , ! this . model . get ( var ) ) ; addBackboneLiteral ( backboneLit ) ; } else { final boolean modelPhase = this . model . get ( var ) ; if ( isBothOrNegativeType ( ) && ! modelPhase || isBothOrPositiveType ( ) && modelPhase ) { final int lit = mkLit ( var , ! modelPhase ) ; if ( ! this . config . isInitialUBCheckForRotatableLiterals ( ) || ! isRotatable ( lit ) ) { this . candidates . add ( lit ) ; } } } } return this . candidates ; }
Creates the initial candidate literals for the backbone computation .
7,468
private boolean solve ( final int lit ) { this . assumptions . push ( not ( lit ) ) ; final boolean sat = solve ( null , this . assumptions ) == Tristate . TRUE ; this . assumptions . pop ( ) ; return sat ; }
Tests the given literal with the formula on the solver for satisfiability .
7,469
private void compute ( final List < Integer > variables ) { final Stack < Integer > candidates = createInitialCandidates ( variables ) ; while ( candidates . size ( ) > 0 ) { final int lit = candidates . pop ( ) ; if ( solve ( lit ) ) { refineUpperBound ( ) ; } else { addBackboneLiteral ( lit ) ; } } }
Computes the backbone for the given variables .
7,470
private LNGIntVector generateClauseVector ( final Formula clause ) { final LNGIntVector clauseVec = new LNGIntVector ( clause . numberOfOperands ( ) ) ; for ( final Literal lit : clause . literals ( ) ) { int index = this . idxForName ( lit . name ( ) ) ; if ( index == - 1 ) { index = this . newVar ( false , true ) ; this . addName ( lit . name ( ) , index ) ; } final int litNum = lit . phase ( ) ? index * 2 : ( index * 2 ) ^ 1 ; clauseVec . push ( litNum ) ; } return clauseVec ; }
Generates a solver vector of a clause .
7,471
private void biasPhases ( ) { final double [ ] score = new double [ 2 * ( maxvar ( ) + 1 ) ] ; for ( final CLClause c : this . clauses ) { if ( c . redundant ( ) || c . satisfied ( ) ) { continue ; } double inc = 1 ; for ( int size = c . size ( ) ; size > 0 ; size -- ) { inc /= 2.0 ; } for ( int i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { final int p = c . lits ( ) . get ( i ) ; if ( p > 0 ) { score [ p * 2 ] += inc ; } else { score [ ( - p * 2 ) - 1 ] += inc ; } } } for ( int idx = 1 ; idx <= maxvar ( ) ; idx ++ ) { this . phases . set ( idx , ( score [ idx * 2 ] > score [ ( idx * 2 ) - 1 ] ) ? ( byte ) 1 : ( byte ) - 1 ) ; } }
Initializes the initial phases of literals .
7,472
private void touch ( final int l ) { int lit = l ; if ( lit < 0 ) { lit = - lit ; } final long newPriority = ( long ) occs ( lit ) . count ( ) + occs ( - lit ) . count ( ) ; if ( ! var ( lit ) . free ( ) ) { return ; } final LNGLongPriorityQueue queue = currentCands ( ) ; queue . update ( lit , - newPriority ) ; if ( this . schedule && ! queue . contains ( lit ) ) { queue . push ( lit ) ; } }
Updates and pushes a literal as candidate to simplify .
7,473
private void touchFixed ( ) { assert this . dense ; assert this . level == 0 ; assert this . schedule ; while ( this . touched < this . trail . size ( ) ) { final int lit = this . trail . get ( this . touched ++ ) ; assert val ( lit ) > 0 ; assert var ( lit ) . level ( ) == 0 ; final CLOccs os = occs ( lit ) ; for ( final CLClause c : os ) { for ( int i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { final int other = c . lits ( ) . get ( i ) ; if ( val ( other ) == VALUE_TRUE ) { continue ; } assert other != lit ; touch ( other ) ; } } } }
Touches literals in newly top - level satisfied clauses using the literals not touched yet .
7,474
private void addOcc ( final int lit , final CLClause c ) { assert this . dense ; occs ( lit ) . add ( c ) ; touch ( lit ) ; }
Adds a clause to a literal s occurrence list .
7,475
private void connectOccs ( final CLClause c ) { assert this . dense ; for ( int i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { addOcc ( c . lits ( ) . get ( i ) , c ) ; } }
Connects a clause through a full occurrence list .
7,476
private void connectOccs ( ) { assert ! this . dense ; this . dense = true ; for ( final CLClause c : this . clauses ) { if ( ! c . redundant ( ) ) { connectOccs ( c ) ; } } }
Connects all clauses through full occurrence lists .
7,477
private void updateGlue ( final CLClause c ) { if ( ! this . config . glueupdate ) { return ; } if ( ! this . config . gluered ) { assert c . glue ( ) == 0 ; return ; } assert this . frames . empty ( ) ; for ( int i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { markFrame ( c . lits ( ) . get ( i ) ) ; } final int newGlue = unmarkFrames ( ) ; if ( newGlue >= c . glue ( ) ) { return ; } c . setGlue ( newGlue ) ; this . stats . gluesSum += newGlue ; this . stats . gluesCount ++ ; this . stats . gluesUpdates ++ ; }
Updates the glue value for a given clause .
7,478
private void dumpClause ( final CLClause c ) { if ( c . dumped ( ) ) { return ; } if ( c . redundant ( ) ) { assert this . stats . clausesRedundant > 0 ; this . stats . clausesRedundant -- ; } else { assert this . stats . clausesIrredundant > 0 ; this . stats . clausesIrredundant -- ; if ( this . dense ) { for ( int i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { decOcc ( c . lits ( ) . get ( i ) ) ; } } } c . setDumped ( true ) ; }
Dumps a given clause .
7,479
private void bumpClause ( final CLClause c ) { switch ( this . config . cbump ) { case INC : c . setActivity ( c . activity ( ) + 1 ) ; break ; case LRU : c . setActivity ( this . stats . conflicts ) ; break ; case AVG : c . setActivity ( ( this . stats . conflicts + c . activity ( ) ) / 2 ) ; break ; case NONE : default : assert this . config . cbump == CleaneLingConfig . ClauseBumping . NONE ; break ; } }
Bumps a clause and increments it s activity .
7,480
private void reduce ( ) { this . stats . reductions ++ ; final LNGVector < CLClause > candidates = new LNGVector < > ( ) ; for ( final CLClause c : this . clauses ) { if ( c . redundant ( ) && ! c . important ( ) && ! c . forcing ( ) ) { candidates . push ( c ) ; } } final int keep = candidates . size ( ) / 2 ; candidates . sort ( CLClause . comp ) ; for ( int i = keep ; i < candidates . size ( ) ; i ++ ) { candidates . get ( i ) . setRemove ( true ) ; } for ( int idx = 1 ; idx <= maxvar ( ) ; idx ++ ) { for ( int sign = - 1 ; sign <= 1 ; sign += 2 ) { final LNGVector < CLWatch > ws = watches ( sign * idx ) ; final LNGVector < CLWatch > newWs = new LNGVector < > ( ws . size ( ) ) ; for ( final CLWatch w : ws ) { if ( ! w . clause ( ) . remove ( ) ) { newWs . push ( w ) ; } } ws . replaceInplace ( newWs ) ; } } int j = 0 ; int i ; for ( i = 0 ; i < this . clauses . size ( ) ; i ++ ) { final CLClause c = this . clauses . get ( i ) ; if ( i == this . distilled ) { this . distilled = j ; } if ( ! c . remove ( ) ) { this . clauses . set ( j ++ , c ) ; } } if ( i == this . distilled ) { this . distilled = j ; } this . clauses . shrinkTo ( j ) ; long reduced = 0 ; for ( int k = keep ; k < candidates . size ( ) ; k ++ ) { deleteClause ( candidates . get ( k ) ) ; reduced ++ ; } this . stats . clausesReduced += reduced ; candidates . release ( ) ; this . limits . reduceRedundant += this . config . redinc ; }
Reduces the number of redundant clauses .
7,481
private int remainingVars ( ) { int res = maxvar ( ) ; res -= this . stats . varsFixed ; res -= this . stats . varsEquivalent ; res -= this . stats . varsEliminated ; return res ; }
Returns the number of remaining variables without fixed and eliminated .
7,482
private void strengthen ( final CLClause c , final int remove ) { if ( c . dumped ( ) || satisfied ( c ) ) { return ; } assert this . addedlits . empty ( ) ; for ( int i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { final int lit = c . lits ( ) . get ( i ) ; if ( lit != remove && val ( lit ) == 0 ) { this . addedlits . push ( lit ) ; } } newPushConnectClause ( ) ; this . addedlits . clear ( ) ; dumpClause ( c ) ; }
Removes a literal in a clause .
7,483
private int sizePenalty ( ) { long numClauses = ( long ) this . stats . clausesIrredundant / this . config . sizepen ; int logres = 0 ; while ( numClauses != 0 && logres < this . config . sizemaxpen ) { numClauses >>= 1 ; logres ++ ; } return 1 << logres ; }
Reduces simplification steps for large formulas .
7,484
private void backward ( final CLClause c , final int ignore ) { int minlit = 0 ; int minoccs = Integer . MAX_VALUE ; int litoccs ; this . stats . steps ++ ; for ( int i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { final int lit = c . lits ( ) . get ( i ) ; if ( lit == ignore ) { continue ; } if ( val ( lit ) < 0 ) { continue ; } litoccs = occs ( lit ) . count ( ) ; if ( minlit != 0 && minoccs >= litoccs ) { continue ; } minlit = lit ; minoccs = litoccs ; } if ( minoccs >= this . config . bwocclim ) { return ; } assert minlit != 0 ; for ( int i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { mark ( c . lits ( ) . get ( i ) ) ; } final CLOccs os = occs ( minlit ) ; for ( final CLClause d : os ) { if ( d == c ) { continue ; } int lit ; int count = this . seen . size ( ) ; int negated = 0 ; this . stats . steps ++ ; for ( int p = 0 ; count != 0 && p < d . lits ( ) . size ( ) ; p ++ ) { lit = d . lits ( ) . get ( p ) ; final int m = marked ( lit ) ; if ( m == 0 ) { continue ; } assert count > 0 ; count -- ; if ( m > 0 ) { continue ; } assert m < 0 ; if ( negated != 0 ) { count = Integer . MAX_VALUE ; break ; } negated = lit ; } if ( count != 0 ) { continue ; } if ( negated != 0 ) { this . tostrengthen . push ( new Pair < > ( d , negated ) ) ; this . stats . backwardStrengthened ++ ; } else { this . stats . backwardSubsumed ++ ; dumpClause ( d ) ; } } unmark ( ) ; }
Backward subsumes from clause .
7,485
private void backward ( final int lit ) { assert this . level == 0 ; assert this . dense ; assert this . tostrengthen . empty ( ) ; final CLOccs os = occs ( lit ) ; for ( final CLClause c : os ) { assert ! c . redundant ( ) ; this . stats . steps ++ ; if ( c . dumped ( ) ) { continue ; } if ( c . size ( ) >= this . config . bwclslim ) { continue ; } if ( satisfied ( c ) ) { continue ; } backward ( c , lit ) ; } while ( ! this . tostrengthen . empty ( ) ) { final Pair < CLClause , Integer > cplp = this . tostrengthen . back ( ) ; this . tostrengthen . pop ( ) ; strengthen ( cplp . first ( ) , cplp . second ( ) ) ; } }
Backward subsumes from clauses in the occurrence list of a given literal .
7,486
private boolean tryElim ( final int cand ) { assert var ( cand ) . free ( ) ; final CLOccs p = occs ( cand ) ; final CLOccs n = occs ( - cand ) ; long limit = ( long ) p . count ( ) + n . count ( ) ; for ( int i = 0 ; limit >= 0 && i < p . clauses ( ) . size ( ) ; i ++ ) { final CLClause c = p . clauses ( ) . get ( i ) ; assert ! c . redundant ( ) ; this . stats . steps ++ ; if ( c . dumped ( ) || satisfied ( c ) ) { continue ; } for ( int j = 0 ; limit >= 0 && j < n . clauses ( ) . size ( ) ; j ++ ) { final CLClause d = n . clauses ( ) . get ( j ) ; assert ! d . redundant ( ) ; this . stats . steps ++ ; if ( d . dumped ( ) || satisfied ( d ) ) { continue ; } if ( tryResolve ( c , cand , d ) ) { limit -- ; } } } return limit >= 0 ; }
Tries bounded variable elimination on a candidate literal .
7,487
private void doResolve ( final CLClause c , final int pivot , final CLClause d ) { assert ! c . dumped ( ) && ! c . satisfied ( ) ; assert ! d . dumped ( ) && ! d . satisfied ( ) ; assert this . addedlits . empty ( ) ; this . stats . steps ++ ; for ( int i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { final int lit = c . lits ( ) . get ( i ) ; if ( lit != pivot ) { this . addedlits . push ( lit ) ; } } this . stats . steps ++ ; for ( int i = 0 ; i < d . lits ( ) . size ( ) ; i ++ ) { final int lit = d . lits ( ) . get ( i ) ; if ( lit != - pivot ) { this . addedlits . push ( lit ) ; } } if ( ! trivialClause ( ) ) { newPushConnectClause ( ) ; } this . addedlits . clear ( ) ; }
Performs resolution on two given clauses and a pivot literal .
7,488
private void pushExtension ( final CLClause c , final int blit ) { pushExtension ( 0 ) ; for ( int i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { final int lit = c . lits ( ) . get ( i ) ; if ( lit != blit ) { pushExtension ( lit ) ; } } pushExtension ( blit ) ; }
Pushes and logs a clause and its blocking literal to the extension .
7,489
private void doElim ( final int cand ) { assert this . schedule ; assert var ( cand ) . free ( ) ; final CLOccs p = occs ( cand ) ; final CLOccs n = occs ( - cand ) ; for ( final CLClause c : p ) { this . stats . steps ++ ; if ( c . dumped ( ) || satisfied ( c ) ) { continue ; } for ( final CLClause d : n ) { this . stats . steps ++ ; if ( d . dumped ( ) || satisfied ( d ) ) { continue ; } doResolve ( c , cand , d ) ; } } final int extend ; final CLOccs e ; if ( p . count ( ) < n . count ( ) ) { extend = cand ; e = p ; } else { extend = - cand ; e = n ; } for ( final CLClause c : e ) { if ( c . dumped ( ) || satisfied ( c ) ) { continue ; } this . stats . steps ++ ; pushExtension ( c , extend ) ; } pushExtension ( 0 ) ; pushExtension ( - extend ) ; while ( ! p . clauses ( ) . empty ( ) ) { final CLClause c = p . clauses ( ) . back ( ) ; this . stats . steps ++ ; p . clauses ( ) . pop ( ) ; if ( c . satisfied ( ) || c . dumped ( ) ) { continue ; } this . stats . clausesEliminated ++ ; dumpClause ( c ) ; } p . clauses ( ) . release ( ) ; while ( ! n . clauses ( ) . empty ( ) ) { final CLClause c = n . clauses ( ) . back ( ) ; this . stats . steps ++ ; n . clauses ( ) . pop ( ) ; if ( c . satisfied ( ) || c . dumped ( ) ) { continue ; } this . stats . clausesEliminated ++ ; dumpClause ( c ) ; } n . clauses ( ) . release ( ) ; var ( cand ) . setState ( CLVar . State . ELIMINATED ) ; this . stats . varsEliminated ++ ; final CLClause conflict = bcp ( ) ; if ( conflict != null ) { analyze ( conflict ) ; assert this . empty != null ; } touchFixed ( ) ; }
Performs blocking variable elimination on a candidate .
7,490
private void dumpEliminatedRedundant ( ) { for ( final CLClause c : this . clauses ) { if ( ! c . redundant ( ) || c . satisfied ( ) || c . dumped ( ) ) { continue ; } if ( containsEliminated ( c ) ) { dumpClause ( c ) ; } } }
Dumps redundant clauses with eliminated variables .
7,491
private void updateCands ( ) { if ( ! this . dense ) { connectOccs ( ) ; } assert ! this . schedule ; this . schedule = true ; if ( this . schedule = currentCands ( ) . empty ( ) ) { for ( int idx = 1 ; idx <= maxvar ( ) ; idx ++ ) { touch ( idx ) ; } } this . schedule = true ; touchFixed ( ) ; }
Updates the candidates priority queue for new rounds of simplification .
7,492
private void blockLit ( final int blit ) { final CLOccs os = occs ( blit ) ; for ( final CLClause c : os ) { assert ! c . redundant ( ) ; if ( ! blockClause ( c , blit ) ) { continue ; } this . stats . clausesBlocked ++ ; pushExtension ( c , blit ) ; dumpClause ( c ) ; } }
Finds and removes all blocked clauses blocked on a given blocking literal .
7,493
private void block ( ) { final long steps = this . limits . simpSteps ; assert this . level == 0 ; assert ! this . config . plain ; if ( ! this . config . block ) { return ; } if ( this . config . blkwait >= this . stats . simplifications ) { return ; } assert this . simplifier == Simplifier . TOPSIMP ; this . simplifier = Simplifier . BLOCK ; updateCands ( ) ; final long limit ; if ( this . stats . simplifications <= this . config . blkrtc ) { limit = Long . MAX_VALUE ; } else { limit = this . stats . steps + 10 * steps / sizePenalty ( ) ; } while ( this . empty == null && ! this . candsBlock . empty ( ) && this . stats . steps ++ < limit ) { final int cand = this . candsBlock . top ( ) ; final long priority = this . candsBlock . priority ( cand ) ; this . candsBlock . pop ( cand ) ; if ( priority == 0 || ! var ( cand ) . free ( ) ) { continue ; } blockLit ( cand ) ; blockLit ( - cand ) ; } assert this . schedule ; this . schedule = false ; assert this . simplifier == Simplifier . BLOCK ; this . simplifier = Simplifier . TOPSIMP ; }
Blocked Clause Elimination .
7,494
private void disconnectClauses ( ) { this . limits . reduceImportant = 0 ; for ( int idx = 1 ; idx <= maxvar ( ) ; idx ++ ) { for ( int sign = - 1 ; sign <= 1 ; sign += 2 ) { final int lit = sign * idx ; watches ( lit ) . release ( ) ; occs ( lit ) . release ( ) ; } } this . dense = false ; }
Disconnects all clauses .
7,495
private CLClause reduceClause ( final CLClause c ) { int lit ; int i ; for ( i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { lit = c . lits ( ) . get ( i ) ; if ( val ( lit ) < 0 ) { break ; } } if ( i == c . lits ( ) . size ( ) ) { return c ; } assert this . addedlits . empty ( ) ; for ( i = 0 ; i < c . lits ( ) . size ( ) ; i ++ ) { lit = c . lits ( ) . get ( i ) ; if ( val ( lit ) >= 0 ) { this . addedlits . push ( lit ) ; } } final boolean redundant = c . redundant ( ) ; final int glue = c . glue ( ) ; deleteClause ( c ) ; final CLClause res = newClause ( redundant , glue ) ; this . addedlits . clear ( ) ; return res ; }
Removes false literals from a given clause .
7,496
private Tristate simplify ( ) { assert this . simplifier == Simplifier . NOSIMP ; this . simplifier = Simplifier . TOPSIMP ; this . stats . simplifications ++ ; backtrack ( ) ; final int varsBefore = remainingVars ( ) ; if ( ! this . config . plain ) { if ( this . empty == null ) { distill ( ) ; } if ( this . empty == null ) { block ( ) ; } if ( this . empty == null ) { elim ( ) ; } } collect ( ) ; assert this . simplifier == Simplifier . TOPSIMP ; this . simplifier = Simplifier . NOSIMP ; final int varsAfter = remainingVars ( ) ; assert varsBefore >= varsAfter ; this . limits . simpRemovedVars = varsBefore - varsAfter ; return this . empty != null ? FALSE : UNDEF ; }
Performs bounded inprocessing .
7,497
private void extend ( ) { while ( ! this . extension . empty ( ) ) { final int lit = this . extension . back ( ) ; int other ; boolean satisfied = false ; while ( ( other = this . extension . back ( ) ) != 0 ) { this . extension . pop ( ) ; if ( val ( other ) == VALUE_TRUE ) { satisfied = true ; } } this . extension . pop ( ) ; if ( ! satisfied ) { this . vals . set ( Math . abs ( lit ) , sign ( lit ) ) ; } } }
Extends a partial to a full assignment .
7,498
public static < T > Set < Set < Node < T > > > compute ( final Graph < T > graph ) { final Set < Set < Node < T > > > connectedComponents = new LinkedHashSet < > ( ) ; final Set < Node < T > > unmarkedNodes = new LinkedHashSet < > ( graph . nodes ( ) ) ; while ( ! unmarkedNodes . isEmpty ( ) ) { Set < Node < T > > connectedComp = new LinkedHashSet < > ( ) ; deepFirstSearch ( unmarkedNodes . iterator ( ) . next ( ) , connectedComp , unmarkedNodes ) ; connectedComponents . add ( connectedComp ) ; } return connectedComponents ; }
Computes the set of connected components of a graph where each component is represented by a set of nodes .
7,499
private void resize ( final int ns ) { final int size = BDDPrime . primeGTE ( ns ) ; this . table = new BDDCacheEntry [ size ] ; for ( int n = 0 ; n < size ; n ++ ) this . table [ n ] = new BDDCacheEntry ( ) ; }
Resizes the cache to a new number of entries . The old cache entries are removed in this process .