idx
int64
0
41.2k
question
stringlengths
83
4.15k
target
stringlengths
5
715
7,300
private static Source createSafeSource ( XMLReader reader , InputSource source ) { try { reader . setFeature ( "http://xml.org/sax/features/external-general-entities" , false ) ; } catch ( SAXException ignored ) { } try { reader . setFeature ( "http://xml.org/sax/features/external-parameter-entities" , false ) ; } catc...
Converts a Source into a Source that is protected against XXE attacks .
7,301
@ edu . umd . cs . findbugs . annotations . SuppressWarnings ( { "DM_DEFAULT_ENCODING" , "OS_OPEN_STREAM" } ) private static void getUlimit ( PrintWriter writer ) throws IOException { InputStream is = new ProcessBuilder ( "bash" , "-c" , "ulimit -a" ) . start ( ) . getInputStream ( ) ; try { BufferedReader bufferedRead...
This method executes the command bash - c ulimit - a on the machine .
7,302
public void addExtendedInformation ( String key , Object value ) { if ( extendedInformation == null ) { extendedInformation = new HashMap < > ( ) ; } extendedInformation . put ( key , value ) ; }
add more extended information to the response
7,303
public synchronized void flush ( ) throws IOException { ensureOpen ( ) ; if ( decodedBuf . position ( ) > 0 ) { decodedBuf . flip ( ) ; String contents = decodedBuf . toString ( ) ; String filtered = contentFilter . filter ( contents ) ; out . write ( filtered . getBytes ( charset ) ) ; decodedBuf . clear ( ) ; } out ....
Flushes the current buffered contents and filters them as is .
7,304
public synchronized void reset ( ) { ensureOpen ( ) ; encodedBuf . clear ( ) ; if ( decodedBuf . capacity ( ) > FilteredConstants . DEFAULT_DECODER_CAPACITY ) { this . decodedBuf = CharBuffer . allocate ( FilteredConstants . DEFAULT_DECODER_CAPACITY ) ; } else { decodedBuf . clear ( ) ; } decoder . reset ( ) ; }
Resets the state of this stream s decoders and buffers .
7,305
private Set < String > getActiveCacheKeys ( final List < Node > nodes ) { Set < String > cacheKeys = new HashSet < > ( nodes . size ( ) ) ; for ( Node node : nodes ) { String cacheKey = Util . getDigestOf ( node . getNodeName ( ) + ":" + ( ( hudson . model . Slave ) node ) . getRemoteFS ( ) ) ; LOGGER . log ( Level . F...
Build a Set including the cacheKeys associated to every agent in the instance
7,306
static boolean mayBeDate ( String s ) { if ( s == null || s . length ( ) != "yyyy-MM-dd_HH-mm-ss" . length ( ) ) { return false ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { switch ( s . charAt ( i ) ) { case '-' : switch ( i ) { case 4 : case 7 : case 13 : case 16 : break ; default : return false ; } break ; cas...
A pre - check to see if a string is a build timestamp formatted date .
7,307
private static Iterable < PluginWrapper > getPluginsSorted ( ) { PluginManager pluginManager = Jenkins . getInstance ( ) . getPluginManager ( ) ; return getPluginsSorted ( pluginManager ) ; }
Fixes JENKINS - 47779 caused by JENKINS - 47713 Not using SortedSet because of PluginWrapper doesn t implements equals and hashCode .
7,308
protected static void showUsage ( Class < ? extends ExampleBase > commandClass ) { System . err . println ( USAGE_STR + commandClass . getName ( ) ) ; }
Prints out how to run the program
7,309
protected static String responseToJson ( Response response ) throws JsonProcessingException { ObjectMapper mapper = ApiModelMixinModule . setupObjectMapper ( new ObjectMapper ( ) ) ; mapper . enable ( SerializationFeature . INDENT_OUTPUT ) ; mapper . setSerializationInclusion ( JsonInclude . Include . NON_NULL ) ; retu...
Converts a response to JSON string
7,310
private static void replaceWords ( StringBuilder input , String [ ] words , String [ ] replaces , boolean ignoreCase ) { if ( input == null || input . length ( ) == 0 || words == null || words . length == 0 || replaces == null || replaces . length == 0 ) { return ; } if ( words . length != replaces . length ) { throw n...
To avoid repeat this code above
7,311
private ServicesData connectorsToCredHub ( CloudFoundryRawServiceData rawServiceData ) { ServicesData servicesData = new ServicesData ( ) ; servicesData . putAll ( rawServiceData ) ; return servicesData ; }
Convert from the Spring Cloud Connectors service data structure to the Spring Credhub data structure .
7,312
private CloudFoundryRawServiceData credHubToConnectors ( ServicesData interpolatedData ) { CloudFoundryRawServiceData rawServicesData = new CloudFoundryRawServiceData ( ) ; rawServicesData . putAll ( interpolatedData ) ; return rawServicesData ; }
Convert from the Spring Credhub service data structure to the Spring Cloud Connectors data structure .
7,313
public static void throwExceptionOnError ( ResponseEntity < ? > response ) { if ( ! response . getStatusCode ( ) . equals ( HttpStatus . OK ) ) { throw new CredHubException ( response . getStatusCode ( ) ) ; } }
Helper method to throw an appropriate exception if a request to CredHub returns with an error code .
7,314
public static Mono < Throwable > buildError ( ClientResponse response ) { return Mono . error ( new CredHubException ( response . statusCode ( ) ) ) ; }
Helper method to return an appropriate error if a request to CredHub returns with an error code .
7,315
public static Actor app ( String appId ) { Assert . notNull ( appId , "appId must not be null" ) ; return new Actor ( APP , appId ) ; }
Create an application identifier . An application is identified by a GUID generated by Cloud Foundry when the application is created .
7,316
public static Actor user ( String userId ) { Assert . notNull ( userId , "userId must not be null" ) ; return new Actor ( USER , userId ) ; }
Create a user identifier . A user is identified by a GUID generated by UAA when a user account is created .
7,317
public static Actor user ( String zoneId , String userId ) { Assert . notNull ( zoneId , "zoneId must not be null" ) ; Assert . notNull ( userId , "userId must not be null" ) ; return new Actor ( USER , zoneId + "/" + userId ) ; }
Create a user identifier . A user is identified by a GUID generated by UAA when a user account is created and the ID of the identity zone the user was created in .
7,318
public static Actor client ( String clientId ) { Assert . notNull ( clientId , "clientId must not be null" ) ; return new Actor ( OAUTH_CLIENT , clientId ) ; }
Create an OAuth2 client identifier . A client identified by user - provided identifier .
7,319
public static Actor client ( String zoneId , String clientId ) { Assert . notNull ( zoneId , "zoneId must not be null" ) ; Assert . notNull ( clientId , "clientId must not be null" ) ; return new Actor ( OAUTH_CLIENT , zoneId + "/" + clientId ) ; }
Create an OAuth2 client identifier . A client identified by user - provided identifier and the ID of the identity zone the client was created in .
7,320
@ JsonGetter ( "operations" ) private List < String > getOperationsAsString ( ) { if ( operations == null ) { return null ; } List < String > operationValues = new ArrayList < > ( operations . size ( ) ) ; for ( Operation operation : operations ) { operationValues . add ( operation . operation ( ) ) ; } return operatio...
Get the set of operations that the actor will be allowed to perform on the credential .
7,321
public ClientHttpResponse intercept ( HttpRequest request , byte [ ] body , ClientHttpRequestExecution execution ) throws IOException { HttpRequestWrapper requestWrapper = new HttpRequestWrapper ( request ) ; HttpHeaders headers = requestWrapper . getHeaders ( ) ; headers . setBearerAuth ( getAccessToken ( ) . getToken...
Add an OAuth2 bearer token header to each request .
7,322
protected Path copyLocalFile ( URL fileUrl ) throws IOException , PluginException { Path destination = Files . createTempDirectory ( "pf4j-update-downloader" ) ; destination . toFile ( ) . deleteOnExit ( ) ; try { Path fromFile = Paths . get ( fileUrl . toURI ( ) ) ; String path = fileUrl . getPath ( ) ; String fileNam...
Efficient copy of file in case of local file system .
7,323
protected Path downloadFileHttp ( URL fileUrl ) throws IOException , PluginException { Path destination = Files . createTempDirectory ( "pf4j-update-downloader" ) ; destination . toFile ( ) . deleteOnExit ( ) ; String path = fileUrl . getPath ( ) ; String fileName = path . substring ( path . lastIndexOf ( '/' ) + 1 ) ;...
Downloads file from HTTP or FTP .
7,324
public List < PluginInfo > getUpdates ( ) { List < PluginInfo > updates = new ArrayList < > ( ) ; for ( PluginWrapper installed : pluginManager . getPlugins ( ) ) { String pluginId = installed . getPluginId ( ) ; if ( hasPluginUpdate ( pluginId ) ) { updates . add ( getPluginsMap ( ) . get ( pluginId ) ) ; } } return u...
Return a list of plugins that are newer versions of already installed plugins .
7,325
public List < PluginInfo > getPlugins ( ) { List < PluginInfo > list = new ArrayList < > ( getPluginsMap ( ) . values ( ) ) ; Collections . sort ( list ) ; return list ; }
Get the list of plugins from all repos .
7,326
public Map < String , PluginInfo > getPluginsMap ( ) { Map < String , PluginInfo > pluginsMap = new HashMap < > ( ) ; for ( UpdateRepository repository : getRepositories ( ) ) { pluginsMap . putAll ( repository . getPlugins ( ) ) ; } return pluginsMap ; }
Get a map of all plugins from all repos where key is plugin id .
7,327
public void addRepository ( UpdateRepository newRepo ) { for ( UpdateRepository ur : repositories ) { if ( ur . getId ( ) . equals ( newRepo . getId ( ) ) ) { throw new RuntimeException ( "Repository with id " + newRepo . getId ( ) + " already exists" ) ; } } newRepo . refresh ( ) ; repositories . add ( newRepo ) ; }
Add a repo that was created by client .
7,328
public void removeRepository ( String id ) { for ( UpdateRepository repo : getRepositories ( ) ) { if ( id . equals ( repo . getId ( ) ) ) { repositories . remove ( repo ) ; break ; } } log . warn ( "Repository with id " + id + " not found, doing nothing" ) ; }
Remove a repository by id .
7,329
public synchronized void refresh ( ) { if ( repositoriesJson != null ) { initRepositoriesFromJson ( ) ; } for ( UpdateRepository updateRepository : repositories ) { updateRepository . refresh ( ) ; } lastPluginRelease . clear ( ) ; }
Refreshes all repositories so they are forced to refresh list of plugins .
7,330
public synchronized boolean installPlugin ( String id , String version ) throws PluginException { Path downloaded = downloadPlugin ( id , version ) ; Path pluginsRoot = pluginManager . getPluginsRoot ( ) ; Path file = pluginsRoot . resolve ( downloaded . getFileName ( ) ) ; try { Files . move ( downloaded , file ) ; } ...
Installs a plugin by id and version .
7,331
protected FileVerifier getFileVerifier ( String pluginId ) { for ( UpdateRepository ur : repositories ) { if ( ur . getPlugin ( pluginId ) != null && ur . getFileVerfier ( ) != null ) { return ur . getFileVerfier ( ) ; } } return new CompoundVerifier ( ) ; }
Gets a file verifier to use for this plugin . First tries to use custom verifier configured for the repository then fallback to the default CompoundVerifier
7,332
protected PluginRelease findReleaseForPlugin ( String id , String version ) throws PluginException { PluginInfo pluginInfo = getPluginsMap ( ) . get ( id ) ; if ( pluginInfo == null ) { log . info ( "Plugin with id {} does not exist in any repository" , id ) ; throw new PluginException ( "Plugin with id {} not found in...
Resolves Release from id and version .
7,333
public PluginRelease getLastPluginRelease ( String id ) { PluginInfo pluginInfo = getPluginsMap ( ) . get ( id ) ; if ( pluginInfo == null ) { return null ; } if ( ! lastPluginRelease . containsKey ( id ) ) { for ( PluginRelease release : pluginInfo . releases ) { if ( systemVersion . equals ( "0.0.0" ) || versionManag...
Returns the last release version of this plugin for given system version regardless of release date .
7,334
public boolean hasPluginUpdate ( String id ) { PluginInfo pluginInfo = getPluginsMap ( ) . get ( id ) ; if ( pluginInfo == null ) { return false ; } String installedVersion = pluginManager . getPlugin ( id ) . getDescriptor ( ) . getVersion ( ) ; PluginRelease last = getLastPluginRelease ( id ) ; return last != null &&...
Finds whether the newer version of the plugin .
7,335
private List < Variable > force ( final Formula formula , final Hypergraph < Variable > hypergraph , final Map < Variable , HypergraphNode < Variable > > nodes ) { final LinkedHashMap < HypergraphNode < Variable > , Integer > initialOrdering = createInitialOrdering ( formula , nodes ) ; LinkedHashMap < HypergraphNode <...
Executes the main FORCE algorithm .
7,336
private LinkedHashMap < HypergraphNode < Variable > , Integer > createInitialOrdering ( final Formula formula , final Map < Variable , HypergraphNode < Variable > > nodes ) { final LinkedHashMap < HypergraphNode < Variable > , Integer > initialOrdering = new LinkedHashMap < > ( ) ; final List < Variable > dfsOrder = th...
Creates an initial ordering for the variables based on a DFS .
7,337
private LinkedHashMap < HypergraphNode < Variable > , Integer > orderingFromTentativeNewLocations ( final LinkedHashMap < HypergraphNode < Variable > , Double > newLocations ) { final LinkedHashMap < HypergraphNode < Variable > , Integer > ordering = new LinkedHashMap < > ( ) ; final List < Map . Entry < HypergraphNode...
Generates a new integer ordering from tentative new locations of nodes with the double weighting .
7,338
public void addEdge ( final Collection < HypergraphNode < T > > nodes ) { final HypergraphEdge < T > edge = new HypergraphEdge < > ( nodes ) ; this . nodes . addAll ( nodes ) ; this . edges . add ( edge ) ; }
Adds an edges to the hypergraph . The edge is represented by its connected nodes .
7,339
protected String naryOperator ( final NAryOperator operator , final String opString ) { final List < Formula > operands = new ArrayList < > ( ) ; for ( final Formula op : operator ) { operands . add ( op ) ; } final int size = operator . numberOfOperands ( ) ; Collections . sort ( operands , this . comparator ) ; final...
Returns the sorted string representation of an n - ary operator .
7,340
protected String pbLhs ( final Literal [ ] operands , final int [ ] coefficients ) { assert operands . length == coefficients . length ; final List < Literal > sortedOperands = new ArrayList < > ( ) ; final List < Integer > sortedCoefficients = new ArrayList < > ( ) ; final List < Literal > givenOperands = Arrays . asL...
Returns the sorted string representation of the left - hand side of a pseudo - Boolean constraint .
7,341
private String sortedEquivalence ( final Equivalence equivalence ) { final Formula right ; final Formula left ; if ( this . comparator . compare ( equivalence . left ( ) , equivalence . right ( ) ) <= 0 ) { right = equivalence . right ( ) ; left = equivalence . left ( ) ; } else { right = equivalence . left ( ) ; left ...
Returns the string representation of an equivalence .
7,342
public void insert ( int n ) { this . indices . growTo ( n + 1 , - 1 ) ; assert ! this . inHeap ( n ) ; this . indices . set ( n , this . heap . size ( ) ) ; this . heap . push ( n ) ; this . percolateUp ( this . indices . get ( n ) ) ; }
Inserts a given element in the heap .
7,343
public int removeMin ( ) { int x = this . heap . get ( 0 ) ; this . heap . set ( 0 , this . heap . back ( ) ) ; this . indices . set ( this . heap . get ( 0 ) , 0 ) ; this . indices . set ( x , - 1 ) ; this . heap . pop ( ) ; if ( this . heap . size ( ) > 1 ) this . percolateDown ( 0 ) ; return x ; }
Removes the minimal element of the heap .
7,344
public void remove ( int n ) { assert this . inHeap ( n ) ; int kPos = this . indices . get ( n ) ; this . indices . set ( n , - 1 ) ; if ( kPos < this . heap . size ( ) - 1 ) { this . heap . set ( kPos , this . heap . back ( ) ) ; this . indices . set ( this . heap . get ( kPos ) , kPos ) ; this . heap . pop ( ) ; thi...
Removes a given element of the heap .
7,345
public void build ( final LNGIntVector ns ) { for ( int i = 0 ; i < this . heap . size ( ) ; i ++ ) this . indices . set ( this . heap . get ( i ) , - 1 ) ; this . heap . clear ( ) ; for ( int i = 0 ; i < ns . size ( ) ; i ++ ) { this . indices . set ( ns . get ( i ) , i ) ; this . heap . push ( ns . get ( i ) ) ; } fo...
Rebuilds the heap from a given vector of elements .
7,346
public void clear ( ) { for ( int i = 0 ; i < this . heap . size ( ) ; i ++ ) this . indices . set ( this . heap . get ( i ) , - 1 ) ; this . heap . clear ( ) ; }
Clears the heap .
7,347
private void percolateUp ( int pos ) { int x = this . heap . get ( pos ) ; int p = parent ( pos ) ; int j = pos ; while ( j != 0 && this . s . lt ( x , this . heap . get ( p ) ) ) { this . heap . set ( j , this . heap . get ( p ) ) ; this . indices . set ( this . heap . get ( p ) , j ) ; j = p ; p = parent ( p ) ; } th...
Bubbles a element at a given position up .
7,348
private void percolateDown ( int pos ) { int p = pos ; int y = this . heap . get ( p ) ; while ( left ( p ) < this . heap . size ( ) ) { int child = right ( p ) < this . heap . size ( ) && this . s . lt ( this . heap . get ( right ( p ) ) , this . heap . get ( left ( p ) ) ) ? right ( p ) : left ( p ) ; if ( ! this . s...
Bubbles a element at a given position down .
7,349
public static EncodingResult resultForMiniSat ( final FormulaFactory f , final MiniSat miniSat ) { return new EncodingResult ( f , miniSat , null ) ; }
Constructs a new result which adds the result directly to a given MiniSat solver .
7,350
public static EncodingResult resultForCleaneLing ( final FormulaFactory f , final CleaneLing cleaneLing ) { return new EncodingResult ( f , null , cleaneLing ) ; }
Constructs a new result which adds the result directly to a given CleaneLing solver .
7,351
public void addClause ( final Literal ... literals ) { if ( this . miniSat == null && this . cleaneLing == null ) this . result . add ( this . f . clause ( literals ) ) ; else if ( this . miniSat != null ) { final LNGIntVector clauseVec = new LNGIntVector ( literals . length ) ; for ( final Literal lit : literals ) { i...
Adds a clause to the result
7,352
private Formula vec2clause ( final LNGVector < Literal > literals ) { final List < Literal > lits = new ArrayList < > ( literals . size ( ) ) ; for ( final Literal l : literals ) lits . add ( l ) ; return this . f . clause ( lits ) ; }
Returns a clause for a vector of literals .
7,353
public Variable newVariable ( ) { if ( this . miniSat == null && this . cleaneLing == null ) return this . f . newCCVariable ( ) ; else if ( this . miniSat != null ) { final int index = this . miniSat . underlyingSolver ( ) . newVar ( ! this . miniSat . initialPhase ( ) , true ) ; final String name = FormulaFactory . C...
Returns a new auxiliary variable .
7,354
public static MiniSat miniSat ( final FormulaFactory f ) { return new MiniSat ( f , SolverStyle . MINISAT , new MiniSatConfig . Builder ( ) . build ( ) , null ) ; }
Returns a new MiniSat solver .
7,355
public static MiniSat miniSat ( final FormulaFactory f , final MiniSatConfig config ) { return new MiniSat ( f , SolverStyle . MINISAT , config , null ) ; }
Returns a new MiniSat solver with a given configuration .
7,356
public static MiniSat glucose ( final FormulaFactory f ) { return new MiniSat ( f , SolverStyle . GLUCOSE , new MiniSatConfig . Builder ( ) . build ( ) , new GlucoseConfig . Builder ( ) . build ( ) ) ; }
Returns a new Glucose solver .
7,357
public static MiniSat glucose ( final FormulaFactory f , final MiniSatConfig miniSatConfig , final GlucoseConfig glucoseConfig ) { return new MiniSat ( f , SolverStyle . GLUCOSE , miniSatConfig , glucoseConfig ) ; }
Returns a new Glucose solver with a given configuration .
7,358
public static MiniSat miniCard ( final FormulaFactory f ) { return new MiniSat ( f , SolverStyle . MINICARD , new MiniSatConfig . Builder ( ) . build ( ) , null ) ; }
Returns a new MiniCard solver .
7,359
public static MiniSat miniCard ( final FormulaFactory f , final MiniSatConfig config ) { return new MiniSat ( f , SolverStyle . MINICARD , config , null ) ; }
Returns a new MiniCard solver with a given configuration .
7,360
private LNGIntVector generateBlockingClause ( final LNGBooleanVector modelFromSolver , final LNGIntVector relevantVars ) { final LNGIntVector blockingClause ; if ( relevantVars != null ) { blockingClause = new LNGIntVector ( relevantVars . size ( ) ) ; for ( int i = 0 ; i < relevantVars . size ( ) ; i ++ ) { final int ...
Generates a blocking clause from a given model and a set of relevant variables .
7,361
private LNGIntVector generateClauseVector ( final Collection < Literal > literals ) { final LNGIntVector clauseVec = new LNGIntVector ( literals . size ( ) ) ; for ( final Literal lit : literals ) { int index = this . solver . idxForName ( lit . name ( ) ) ; if ( index == - 1 ) { index = this . solver . newVar ( ! this...
Generates a clause vector of a collection of literals .
7,362
public BDD restrict ( final Collection < Literal > restriction ) { final BDD resBDD = this . factory . build ( this . factory . getF ( ) . and ( restriction ) ) ; return new BDD ( this . factory . underlyingKernel ( ) . restrict ( index ( ) , resBDD . index ( ) ) , this . factory ) ; }
Restricts the BDD .
7,363
public BDD exists ( final Collection < Variable > variables ) { final BDD resBDD = this . factory . build ( this . factory . getF ( ) . and ( variables ) ) ; return new BDD ( this . factory . underlyingKernel ( ) . exists ( index ( ) , resBDD . index ( ) ) , this . factory ) ; }
Existential quantifier elimination for a given set of variables .
7,364
public BDD forall ( final Collection < Variable > variables ) { final BDD resBDD = this . factory . build ( this . factory . getF ( ) . and ( variables ) ) ; return new BDD ( this . factory . underlyingKernel ( ) . forAll ( index ( ) , resBDD . index ( ) ) , this . factory ) ; }
Universal quantifier elimination for a given set of variables .
7,365
protected String bracket ( final Formula formula ) { return String . format ( "%s%s%s" , this . lbr ( ) , this . toString ( formula ) , this . rbr ( ) ) ; }
Returns a bracketed string version of a given formula .
7,366
protected String binaryOperator ( final BinaryOperator operator , final String opString ) { final String leftString = operator . type ( ) . precedence ( ) < operator . left ( ) . type ( ) . precedence ( ) ? this . toString ( operator . left ( ) ) : this . bracket ( operator . left ( ) ) ; final String rightString = ope...
Returns the string representation of a binary operator .
7,367
protected String naryOperator ( final NAryOperator operator , final String opString ) { final StringBuilder sb = new StringBuilder ( ) ; int count = 0 ; final int size = operator . numberOfOperands ( ) ; Formula last = null ; for ( final Formula op : operator ) { if ( ++ count == size ) { last = op ; } else { sb . appe...
Returns the string representation of an n - ary operator .
7,368
protected String pbLhs ( final Literal [ ] operands , final int [ ] coefficients ) { assert operands . length == coefficients . length ; final StringBuilder sb = new StringBuilder ( ) ; final String mul = this . pbMul ( ) ; final String add = this . pbAdd ( ) ; for ( int i = 0 ; i < operands . length - 1 ; i ++ ) { if ...
Returns the string representation of the left - hand side of a pseudo - Boolean constraint .
7,369
public DRUPResult compute ( final LNGVector < LNGIntVector > originalProblem , final LNGVector < LNGIntVector > proof ) { final DRUPResult result = new DRUPResult ( ) ; Solver s = new Solver ( originalProblem , proof ) ; boolean parseReturnValue = s . parse ( ) ; if ( ! parseReturnValue ) { result . trivialUnsat = true...
Computes the DRUP result for a given problem in terms of original clauses and the generated proof .
7,370
private int countNonNegativeBits ( final Tristate [ ] bits ) { int result = 0 ; for ( final Tristate bit : bits ) if ( bit != Tristate . FALSE ) result ++ ; return result ; }
Counts the number of non - negative bits of a given tristate vector .
7,371
private long computeUndefNum ( final Tristate [ ] bits ) { long sum = 0 ; for ( int i = bits . length - 1 ; i >= 0 ; i -- ) if ( bits [ i ] == Tristate . UNDEF ) sum += Math . pow ( 2 , bits . length - 1 - i ) ; return sum ; }
Computes a number representing the number and position of the UNDEF states in the bit array .
7,372
Formula translateToFormula ( final List < Variable > varOrder ) { final FormulaFactory f = varOrder . get ( 0 ) . factory ( ) ; assert this . bits . length == varOrder . size ( ) ; final List < Literal > operands = new ArrayList < > ( varOrder . size ( ) ) ; for ( int i = 0 ; i < this . bits . length ; i ++ ) if ( this...
Translates this term to a formula for a given variable ordering
7,373
public static < T > void write ( final String fileName , final Graph < T > graph ) throws IOException { write ( new File ( fileName . endsWith ( ".dot" ) ? fileName : fileName + ".dot" ) , graph ) ; }
Writes a given formula s internal data structure as a dimacs file .
7,374
public static < T > void write ( final File file , final Graph < T > graph ) throws IOException { final StringBuilder sb = new StringBuilder ( String . format ( "strict graph {%n" ) ) ; Set < Node < T > > doneNodes = new LinkedHashSet < > ( ) ; for ( Node < T > d : graph . nodes ( ) ) { for ( Node < T > n : d . neighbo...
Writes a given graph s internal data structure as a dot file .
7,375
public ImmutableFormulaList encode ( final PBConstraint cc ) { final EncodingResult result = EncodingResult . resultForFormula ( f ) ; this . encodeConstraint ( cc , result ) ; return new ImmutableFormulaList ( FType . AND , result . result ( ) ) ; }
Encodes a cardinality constraint and returns its CNF encoding .
7,376
public Pair < ImmutableFormulaList , CCIncrementalData > encodeIncremental ( final PBConstraint cc ) { final EncodingResult result = EncodingResult . resultForFormula ( f ) ; final CCIncrementalData incData = this . encodeIncremental ( cc , result ) ; return new Pair < > ( new ImmutableFormulaList ( FType . AND , resul...
Encodes an incremental cardinality constraint and returns its encoding .
7,377
private void encodeConstraint ( final PBConstraint cc , final EncodingResult result ) { if ( ! cc . isCC ( ) ) throw new IllegalArgumentException ( "Cannot encode a non-cardinality constraint with a cardinality constraint encoder." ) ; final Variable [ ] ops = litsAsVars ( cc . operands ( ) ) ; switch ( cc . comparator...
Encodes the constraint in the given result .
7,378
private void amk ( final EncodingResult result , final Variable [ ] vars , int rhs ) { if ( rhs < 0 ) throw new IllegalArgumentException ( "Invalid right hand side of cardinality constraint: " + rhs ) ; if ( rhs >= vars . length ) return ; if ( rhs == 0 ) { for ( final Variable var : vars ) result . addClause ( var . n...
Encodes an at - most - k constraint .
7,379
private void alk ( final EncodingResult result , final Variable [ ] vars , int rhs ) { if ( rhs < 0 ) throw new IllegalArgumentException ( "Invalid right hand side of cardinality constraint: " + rhs ) ; if ( rhs > vars . length ) { result . addClause ( ) ; return ; } if ( rhs == 0 ) return ; if ( rhs == 1 ) { result . ...
Encodes an at - lest - k constraint .
7,380
private void exk ( final EncodingResult result , final Variable [ ] vars , int rhs ) { if ( rhs < 0 ) throw new IllegalArgumentException ( "Invalid right hand side of cardinality constraint: " + rhs ) ; if ( rhs > vars . length ) { result . addClause ( ) ; return ; } if ( rhs == 0 ) { for ( final Variable var : vars ) ...
Encodes an exactly - k constraint .
7,381
private CCAtMostOne bestAMO ( int n ) { if ( n <= 10 ) { if ( this . amoPure == null ) this . amoPure = new CCAMOPure ( ) ; return this . amoPure ; } else { if ( this . amoProduct == null ) this . amoProduct = new CCAMOProduct ( this . config ( ) . productRecursiveBound ) ; return this . amoProduct ; } }
Returns the best at - most - one encoder for a given number of variables . The valuation is based on theoretical and practical observations . For < = 10 the pure encoding without introduction of new variables is used otherwise the product encoding is chosen .
7,382
public void addWithRelaxation ( final Variable relaxationVar , final ImmutableFormulaList formulas ) { for ( final Formula formula : formulas ) { this . addWithRelaxation ( relaxationVar , formula ) ; } }
Adds a formula list to the solver .
7,383
public void addWithRelaxation ( final Variable relaxationVar , final Collection < ? extends Formula > formulas ) { for ( final Formula formula : formulas ) { this . addWithRelaxation ( relaxationVar , formula ) ; } }
Adds a collection of formulas to the solver .
7,384
private void addClauseSetWithRelaxation ( final Variable relaxationVar , final Formula formula ) { switch ( formula . type ( ) ) { case TRUE : break ; case FALSE : case LITERAL : case OR : this . addClauseWithRelaxation ( relaxationVar , formula ) ; break ; case AND : for ( final Formula op : formula ) { this . addClau...
Adds a formula which is already in CNF with a given relaxation to the solver .
7,385
public List < Assignment > enumerateAllModels ( final ModelEnumerationHandler handler ) { return this . enumerateAllModels ( ( Collection < Variable > ) null , handler ) ; }
Enumerates all models of the current formula and passes it to a model enumeration handler .
7,386
void connectTo ( final Node < T > o ) { if ( ! this . graph . equals ( o . graph ) ) throw new IllegalArgumentException ( "Cannot connect to nodes of two different graphs." ) ; if ( this . equals ( o ) ) { return ; } neighbours . add ( o ) ; }
Adds the given node to the neighbours of this node . Both nodes must be in the same graph .
7,387
protected static double luby ( double y , int x ) { int intX = x ; int size = 1 ; int seq = 0 ; while ( size < intX + 1 ) { seq ++ ; size = 2 * size + 1 ; } while ( size - 1 != intX ) { size = ( size - 1 ) >> 1 ; seq -- ; intX = intX % size ; } return Math . pow ( y , seq ) ; }
Computes the next number in the Luby sequence .
7,388
private void initializeConfig ( ) { this . varDecay = this . config . varDecay ; this . varInc = this . config . varInc ; this . ccminMode = this . config . clauseMin ; this . restartFirst = this . config . restartFirst ; this . restartInc = this . config . restartInc ; this . clauseDecay = this . config . clauseDecay ...
Initializes the solver configuration .
7,389
protected Tristate value ( int lit ) { return sign ( lit ) ? Tristate . negate ( this . v ( lit ) . assignment ( ) ) : this . v ( lit ) . assignment ( ) ; }
Returns the assigned value of a given literal .
7,390
public boolean lt ( int x , int y ) { return this . vars . get ( x ) . activity ( ) > this . vars . get ( y ) . activity ( ) ; }
Compares two variables by their activity .
7,391
public int idxForName ( final String name ) { final Integer id = this . name2idx . get ( name ) ; return id == null ? - 1 : id ; }
Returns the variable index for a given variable name .
7,392
public void addName ( final String name , int id ) { this . name2idx . put ( name , id ) ; this . idx2name . put ( id , name ) ; }
Adds a new variable name with a given variable index to this solver .
7,393
public boolean addClause ( int lit , final Proposition proposition ) { final LNGIntVector unit = new LNGIntVector ( 1 ) ; unit . push ( lit ) ; return this . addClause ( unit , proposition ) ; }
Adds a unit clause to the solver .
7,394
protected int pickBranchLit ( ) { int next = - 1 ; while ( next == - 1 || this . vars . get ( next ) . assignment ( ) != Tristate . UNDEF || ! this . vars . get ( next ) . decision ( ) ) if ( this . orderHeap . empty ( ) ) return - 1 ; else next = this . orderHeap . removeMin ( ) ; return mkLit ( next , this . vars . g...
Picks the next branching literal .
7,395
protected void varBumpActivity ( int v , double inc ) { final MSVariable var = this . vars . get ( v ) ; var . incrementActivity ( inc ) ; if ( var . activity ( ) > 1e100 ) { for ( final MSVariable variable : this . vars ) variable . rescaleActivity ( ) ; this . varInc *= 1e-100 ; } if ( this . orderHeap . inHeap ( v )...
Bumps the activity of the variable at a given index by a given value .
7,396
protected void rebuildOrderHeap ( ) { final LNGIntVector vs = new LNGIntVector ( ) ; for ( int v = 0 ; v < this . nVars ( ) ; v ++ ) if ( this . vars . get ( v ) . decision ( ) && this . vars . get ( v ) . assignment ( ) == Tristate . UNDEF ) vs . push ( v ) ; this . orderHeap . build ( vs ) ; }
Rebuilds the heap of decision variables .
7,397
protected void claBumpActivity ( final MSClause c ) { c . incrementActivity ( claInc ) ; if ( c . activity ( ) > 1e20 ) { for ( final MSClause clause : learnts ) clause . rescaleActivity ( ) ; claInc *= 1e-20 ; } }
Bumps the activity of the given clause .
7,398
public void encode ( final MiniSatStyleSolver s , final LNGIntVector lits ) { assert lits . size ( ) != 0 ; if ( lits . size ( ) == 1 ) addUnitClause ( s , lits . get ( 0 ) ) ; else { final LNGIntVector seqAuxiliary = new LNGIntVector ( ) ; for ( int i = 0 ; i < lits . size ( ) - 1 ; i ++ ) { seqAuxiliary . push ( mkLi...
Encodes and adds the AMO constraint to the given solver .
7,399
public Formula substitute ( final Variable variable , final Formula formula ) { final Substitution subst = new Substitution ( ) ; subst . addMapping ( variable , formula ) ; return this . substitute ( subst ) ; }
Performs a simultaneous substitution on this formula given a single mapping from variable to formula .