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 ) ; } catch ( SAXException ignored ) { } reader . setEntityResolver ( ( publicId , systemId ) -> { return new InputSource ( new ByteArrayInputStream ( XXE_MARKER . getBytes ( StandardCharsets . US_ASCII ) ) ) ; } ) ; return new SAXSource ( reader , source ) ; }
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 bufferedReader = new BufferedReader ( new InputStreamReader ( is ) ) ; String line ; while ( ( line = bufferedReader . readLine ( ) ) != null ) { writer . println ( line ) ; } } finally { is . close ( ) ; } }
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 . flush ( ) ; }
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 . FINEST , "cacheKey {0} is active" , cacheKey ) ; cacheKeys . add ( StringUtils . right ( cacheKey , 8 ) ) ; } return cacheKeys ; }
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 ; case '_' : if ( i != 10 ) { return false ; } break ; case '0' : case '1' : switch ( i ) { case 4 : case 7 : case 10 : case 13 : case 16 : return false ; default : break ; } break ; case '2' : switch ( i ) { case 4 : case 5 : case 7 : case 10 : case 13 : case 16 : return false ; default : break ; } break ; case '3' : switch ( i ) { case 0 : case 4 : case 5 : case 7 : case 10 : case 11 : case 13 : case 16 : return false ; default : break ; } break ; case '4' : case '5' : switch ( i ) { case 0 : case 4 : case 5 : case 7 : case 8 : case 10 : case 11 : case 13 : case 16 : return false ; default : break ; } break ; case '6' : case '7' : case '8' : case '9' : switch ( i ) { case 0 : case 4 : case 5 : case 7 : case 8 : case 10 : case 11 : case 13 : case 14 : case 16 : case 17 : return false ; default : break ; } break ; default : return false ; } } return true ; }
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 ) ; return mapper . writeValueAsString ( response ) ; }
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 new IllegalArgumentException ( String . format ( "Words (%d) and replaces (%d) lengths should be equals" , words . length , replaces . length ) ) ; } for ( int i = 0 ; i < words . length ; i ++ ) { replaceWord ( input , words [ i ] , replaces [ i ] , ignoreCase ) ; } }
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 operationValues ; }
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 ( ) . getTokenValue ( ) ) ; return execution . execute ( requestWrapper , body ) ; }
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 fileName = path . substring ( path . lastIndexOf ( '/' ) + 1 ) ; Path toFile = destination . resolve ( fileName ) ; Files . copy ( fromFile , toFile , StandardCopyOption . COPY_ATTRIBUTES , StandardCopyOption . REPLACE_EXISTING ) ; return toFile ; } catch ( URISyntaxException e ) { throw new PluginException ( "Something wrong with given URL" , e ) ; } }
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 ) ; Path file = destination . resolve ( fileName ) ; URLConnection connection = fileUrl . openConnection ( ) ; connection . connect ( ) ; HttpURLConnection httpConnection = ( HttpURLConnection ) connection ; if ( httpConnection . getResponseCode ( ) == HttpURLConnection . HTTP_UNAUTHORIZED ) { throw new ConnectException ( "HTTP Authorization failure" ) ; } long lastModified = httpConnection . getHeaderFieldDate ( "Last-Modified" , System . currentTimeMillis ( ) ) ; InputStream is = null ; for ( int i = 0 ; i < 3 ; i ++ ) { try { is = connection . getInputStream ( ) ; break ; } catch ( IOException e ) { log . error ( e . getMessage ( ) , e ) ; } } if ( is == null ) { throw new ConnectException ( "Can't get '" + fileUrl + " to '" + file + "'" ) ; } FileOutputStream fos = new FileOutputStream ( file . toFile ( ) ) ; byte [ ] buffer = new byte [ 1024 ] ; int length ; while ( ( length = is . read ( buffer ) ) >= 0 ) { fos . write ( buffer , 0 , length ) ; } fos . close ( ) ; is . close ( ) ; log . debug ( "Set last modified of '{}' to '{}'" , file , lastModified ) ; Files . setLastModifiedTime ( file , FileTime . fromMillis ( lastModified ) ) ; return file ; }
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 updates ; }
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 ) ; } catch ( IOException e ) { throw new PluginException ( e , "Failed to write file '{}' to plugins folder" , file ) ; } String pluginId = pluginManager . loadPlugin ( file ) ; PluginState state = pluginManager . startPlugin ( pluginId ) ; return PluginState . STARTED . equals ( state ) ; }
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 any repository" , id ) ; } if ( version == null ) { return getLastPluginRelease ( id ) ; } for ( PluginRelease release : pluginInfo . releases ) { if ( versionManager . compareVersions ( version , release . version ) == 0 && release . url != null ) { return release ; } } throw new PluginException ( "Plugin {} with version @{} does not exist in the repository" , id , version ) ; }
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" ) || versionManager . checkVersionConstraint ( systemVersion , release . requires ) ) { if ( lastPluginRelease . get ( id ) == null ) { lastPluginRelease . put ( id , release ) ; } else if ( versionManager . compareVersions ( release . version , lastPluginRelease . get ( id ) . version ) > 0 ) { lastPluginRelease . put ( id , release ) ; } } } } return lastPluginRelease . get ( id ) ; }
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 && versionManager . compareVersions ( last . version , installedVersion ) > 0 ; }
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 < Variable > , Integer > lastOrdering ; LinkedHashMap < HypergraphNode < Variable > , Integer > currentOrdering = initialOrdering ; do { lastOrdering = currentOrdering ; final LinkedHashMap < HypergraphNode < Variable > , Double > newLocations = new LinkedHashMap < > ( ) ; for ( final HypergraphNode < Variable > node : hypergraph . nodes ( ) ) newLocations . put ( node , node . computeTentativeNewLocation ( lastOrdering ) ) ; currentOrdering = orderingFromTentativeNewLocations ( newLocations ) ; } while ( shouldProceed ( lastOrdering , currentOrdering ) ) ; final Variable [ ] ordering = new Variable [ currentOrdering . size ( ) ] ; for ( final Map . Entry < HypergraphNode < Variable > , Integer > entry : currentOrdering . entrySet ( ) ) ordering [ entry . getValue ( ) ] = entry . getKey ( ) . content ( ) ; return Arrays . asList ( ordering ) ; }
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 = this . dfsOrdering . getOrder ( formula ) ; for ( int i = 0 ; i < dfsOrder . size ( ) ; i ++ ) initialOrdering . put ( nodes . get ( dfsOrder . get ( i ) ) , i ) ; return initialOrdering ; }
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 < Variable > , Double > > list = new ArrayList < > ( newLocations . entrySet ( ) ) ; Collections . sort ( list , COMPARATOR ) ; int count = 0 ; for ( final Map . Entry < HypergraphNode < Variable > , Double > entry : list ) ordering . put ( entry . getKey ( ) , count ++ ) ; return ordering ; }
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 StringBuilder sb = new StringBuilder ( ) ; int count = 0 ; Formula last = null ; for ( final Formula op : operands ) { if ( ++ count == size ) { last = op ; } else { sb . append ( operator . type ( ) . precedence ( ) < op . type ( ) . precedence ( ) ? toString ( op ) : bracket ( op ) ) ; sb . append ( opString ) ; } } if ( last != null ) { sb . append ( operator . type ( ) . precedence ( ) < last . type ( ) . precedence ( ) ? toString ( last ) : bracket ( last ) ) ; } return sb . toString ( ) ; }
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 . asList ( operands ) ; for ( final Variable v : this . varOrder ) { final int index = givenOperands . indexOf ( v ) ; if ( index != - 1 ) { sortedOperands . add ( v ) ; sortedCoefficients . add ( coefficients [ index ] ) ; } } for ( final Literal givenOperand : givenOperands ) { if ( ! sortedOperands . contains ( givenOperand ) ) { sortedOperands . add ( givenOperand ) ; sortedCoefficients . add ( coefficients [ givenOperands . indexOf ( givenOperand ) ] ) ; } } final StringBuilder sb = new StringBuilder ( ) ; final String mul = pbMul ( ) ; final String add = pbAdd ( ) ; for ( int i = 0 ; i < sortedOperands . size ( ) - 1 ; i ++ ) { if ( sortedCoefficients . get ( i ) != 1 ) { sb . append ( sortedCoefficients . get ( i ) ) . append ( mul ) . append ( sortedOperands . get ( i ) ) . append ( add ) ; } else { sb . append ( sortedOperands . get ( i ) ) . append ( add ) ; } } if ( sortedOperands . size ( ) > 0 ) { if ( sortedCoefficients . get ( sortedOperands . size ( ) - 1 ) != 1 ) { sb . append ( sortedCoefficients . get ( sortedOperands . size ( ) - 1 ) ) . append ( mul ) . append ( sortedOperands . get ( sortedOperands . size ( ) - 1 ) ) ; } else { sb . append ( sortedOperands . get ( sortedOperands . size ( ) - 1 ) ) ; } } return sb . toString ( ) ; }
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 = equivalence . right ( ) ; } final String leftString = FType . EQUIV . precedence ( ) < left . type ( ) . precedence ( ) ? toString ( left ) : bracket ( left ) ; final String rightString = FType . EQUIV . precedence ( ) < right . type ( ) . precedence ( ) ? toString ( right ) : bracket ( right ) ; return String . format ( "%s%s%s" , leftString , equivalence ( ) , rightString ) ; }
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 ( ) ; this . percolateDown ( kPos ) ; } else this . heap . pop ( ) ; }
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 ) ) ; } for ( int i = this . heap . size ( ) / 2 - 1 ; i >= 0 ; i -- ) this . percolateDown ( i ) ; }
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 ) ; } this . heap . set ( j , x ) ; this . indices . set ( x , j ) ; }
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 . lt ( this . heap . get ( child ) , y ) ) break ; this . heap . set ( p , this . heap . get ( child ) ) ; this . indices . set ( this . heap . get ( p ) , p ) ; p = child ; } this . heap . set ( p , y ) ; this . indices . set ( y , p ) ; }
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 ) { int index = this . miniSat . underlyingSolver ( ) . idxForName ( lit . name ( ) ) ; if ( index == - 1 ) { index = this . miniSat . underlyingSolver ( ) . newVar ( ! this . miniSat . initialPhase ( ) , true ) ; this . miniSat . underlyingSolver ( ) . addName ( lit . name ( ) , index ) ; } final int litNum ; if ( lit instanceof EncodingAuxiliaryVariable ) litNum = ! ( ( EncodingAuxiliaryVariable ) lit ) . negated ? index * 2 : ( index * 2 ) ^ 1 ; else litNum = lit . phase ( ) ? index * 2 : ( index * 2 ) ^ 1 ; clauseVec . push ( litNum ) ; } this . miniSat . underlyingSolver ( ) . addClause ( clauseVec , null ) ; this . miniSat . setSolverToUndef ( ) ; } else { for ( final Literal lit : literals ) { final int index = this . cleaneLing . getOrCreateVarIndex ( lit . variable ( ) ) ; if ( lit instanceof EncodingAuxiliaryVariable ) this . cleaneLing . underlyingSolver ( ) . addlit ( ! ( ( EncodingAuxiliaryVariable ) lit ) . negated ? index : - index ) ; else this . cleaneLing . underlyingSolver ( ) . addlit ( lit . phase ( ) ? index : - index ) ; } this . cleaneLing . underlyingSolver ( ) . addlit ( CleaneLing . CLAUSE_TERMINATOR ) ; this . cleaneLing . setSolverToUndef ( ) ; } }
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 . CC_PREFIX + "MINISAT_" + index ; this . miniSat . underlyingSolver ( ) . addName ( name , index ) ; return new EncodingAuxiliaryVariable ( name , false ) ; } else return new EncodingAuxiliaryVariable ( this . cleaneLing . createNewVariableOnSolver ( FormulaFactory . CC_PREFIX + "CLEANELING" ) , false ) ; }
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 varIndex = relevantVars . get ( i ) ; if ( varIndex != - 1 ) { final boolean varAssignment = modelFromSolver . get ( varIndex ) ; blockingClause . push ( varAssignment ? ( varIndex * 2 ) ^ 1 : varIndex * 2 ) ; } } } else { blockingClause = new LNGIntVector ( modelFromSolver . size ( ) ) ; for ( int i = 0 ; i < modelFromSolver . size ( ) ; i ++ ) { final boolean varAssignment = modelFromSolver . get ( i ) ; blockingClause . push ( varAssignment ? ( i * 2 ) ^ 1 : i * 2 ) ; } } return blockingClause ; }
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 . initialPhase , true ) ; this . solver . addName ( lit . name ( ) , index ) ; } final int litNum = lit . phase ( ) ? index * 2 : ( index * 2 ) ^ 1 ; clauseVec . push ( litNum ) ; } return clauseVec ; }
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 = operator . type ( ) . precedence ( ) < operator . right ( ) . type ( ) . precedence ( ) ? this . toString ( operator . right ( ) ) : this . bracket ( operator . right ( ) ) ; return String . format ( "%s%s%s" , leftString , opString , rightString ) ; }
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 . append ( operator . type ( ) . precedence ( ) < op . type ( ) . precedence ( ) ? this . toString ( op ) : this . bracket ( op ) ) ; sb . append ( opString ) ; } } if ( last != null ) { sb . append ( operator . type ( ) . precedence ( ) < last . type ( ) . precedence ( ) ? this . toString ( last ) : this . bracket ( last ) ) ; } return sb . toString ( ) ; }
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 ( coefficients [ i ] != 1 ) { sb . append ( coefficients [ i ] ) . append ( mul ) . append ( operands [ i ] ) . append ( add ) ; } else { sb . append ( operands [ i ] ) . append ( add ) ; } } if ( operands . length > 0 ) { if ( coefficients [ operands . length - 1 ] != 1 ) { sb . append ( coefficients [ operands . length - 1 ] ) . append ( mul ) . append ( operands [ operands . length - 1 ] ) ; } else { sb . append ( operands [ operands . length - 1 ] ) ; } } return sb . toString ( ) ; }
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 ; result . unsatCore = new LNGVector < > ( ) ; } else { result . trivialUnsat = false ; result . unsatCore = s . verify ( ) ; } return result ; }
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 . bits [ i ] != Tristate . UNDEF ) operands . add ( this . bits [ i ] == Tristate . TRUE ? varOrder . get ( i ) : varOrder . get ( i ) . negate ( ) ) ; return f . and ( operands ) ; }
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 . neighbours ( ) ) if ( ! doneNodes . contains ( n ) ) sb . append ( " " ) . append ( d . content ( ) ) . append ( " -- " ) . append ( n . content ( ) ) . append ( System . lineSeparator ( ) ) ; doneNodes . add ( d ) ; } for ( Node < T > d : graph . nodes ( ) ) { if ( d . neighbours ( ) . isEmpty ( ) ) { sb . append ( " " ) . append ( d . content ( ) ) . append ( System . lineSeparator ( ) ) ; } } sb . append ( "}" ) ; try ( BufferedWriter writer = new BufferedWriter ( new OutputStreamWriter ( new FileOutputStream ( file ) , StandardCharsets . UTF_8 ) ) ) { writer . append ( sb ) ; writer . flush ( ) ; } }
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 , result . result ( ) ) , incData ) ; }
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 ( ) ) { case LE : if ( cc . rhs ( ) == 1 ) this . amo ( result , ops ) ; else this . amk ( result , ops , cc . rhs ( ) ) ; break ; case LT : if ( cc . rhs ( ) == 2 ) this . amo ( result , ops ) ; else this . amk ( result , ops , cc . rhs ( ) - 1 ) ; break ; case GE : this . alk ( result , ops , cc . rhs ( ) ) ; break ; case GT : this . alk ( result , ops , cc . rhs ( ) + 1 ) ; break ; case EQ : if ( cc . rhs ( ) == 1 ) this . exo ( result , ops ) ; else this . exk ( result , ops , cc . rhs ( ) ) ; break ; default : throw new IllegalArgumentException ( "Unknown pseudo-Boolean comparator: " + 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 . negate ( ) ) ; return ; } switch ( this . config ( ) . amkEncoder ) { case TOTALIZER : if ( this . amkTotalizer == null ) this . amkTotalizer = new CCAMKTotalizer ( ) ; this . amkTotalizer . build ( result , vars , rhs ) ; break ; case MODULAR_TOTALIZER : if ( this . amkModularTotalizer == null ) this . amkModularTotalizer = new CCAMKModularTotalizer ( this . f ) ; this . amkModularTotalizer . build ( result , vars , rhs ) ; break ; case CARDINALITY_NETWORK : if ( this . amkCardinalityNetwork == null ) this . amkCardinalityNetwork = new CCAMKCardinalityNetwork ( ) ; this . amkCardinalityNetwork . build ( result , vars , rhs ) ; break ; case BEST : this . bestAMK ( vars . length ) . build ( result , vars , rhs ) ; break ; default : throw new IllegalStateException ( "Unknown at-most-k encoder: " + this . config ( ) . amkEncoder ) ; } }
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 . addClause ( ( Literal [ ] ) vars ) ; return ; } if ( rhs == vars . length ) { for ( final Variable var : vars ) result . addClause ( var ) ; return ; } switch ( this . config ( ) . alkEncoder ) { case TOTALIZER : if ( this . alkTotalizer == null ) this . alkTotalizer = new CCALKTotalizer ( ) ; this . alkTotalizer . build ( result , vars , rhs ) ; break ; case MODULAR_TOTALIZER : if ( this . alkModularTotalizer == null ) this . alkModularTotalizer = new CCALKModularTotalizer ( this . f ) ; this . alkModularTotalizer . build ( result , vars , rhs ) ; break ; case CARDINALITY_NETWORK : if ( this . alkCardinalityNetwork == null ) this . alkCardinalityNetwork = new CCALKCardinalityNetwork ( ) ; this . alkCardinalityNetwork . build ( result , vars , rhs ) ; break ; case BEST : this . bestALK ( vars . length ) . build ( result , vars , rhs ) ; break ; default : throw new IllegalStateException ( "Unknown at-least-k encoder: " + this . config ( ) . alkEncoder ) ; } }
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 ) result . addClause ( var . negate ( ) ) ; return ; } if ( rhs == vars . length ) { for ( final Variable var : vars ) result . addClause ( var ) ; return ; } switch ( this . config ( ) . exkEncoder ) { case TOTALIZER : if ( this . exkTotalizer == null ) this . exkTotalizer = new CCEXKTotalizer ( ) ; this . exkTotalizer . build ( result , vars , rhs ) ; break ; case CARDINALITY_NETWORK : if ( this . exkCardinalityNetwork == null ) this . exkCardinalityNetwork = new CCEXKCardinalityNetwork ( ) ; this . exkCardinalityNetwork . build ( result , vars , rhs ) ; break ; case BEST : this . bestEXK ( vars . length ) . build ( result , vars , rhs ) ; break ; default : throw new IllegalStateException ( "Unknown exactly-k encoder: " + this . config ( ) . exkEncoder ) ; } }
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 . addClauseWithRelaxation ( relaxationVar , op ) ; } break ; default : throw new IllegalArgumentException ( "Input formula ist not a valid CNF: " + formula ) ; } }
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 ; this . removeSatisfied = this . config . removeSatisfied ; this . learntsizeFactor = this . config . learntsizeFactor ; this . learntsizeInc = this . config . learntsizeInc ; this . incremental = this . config . incremental ; }
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 . get ( next ) . polarity ( ) ) ; }
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 ) ) this . orderHeap . decrease ( 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 ( mkLit ( s . nVars ( ) , false ) ) ; MaxSAT . newSATVariable ( s ) ; } for ( int i = 0 ; i < lits . size ( ) ; i ++ ) { if ( i == 0 ) { addBinaryClause ( s , lits . get ( i ) , not ( seqAuxiliary . get ( i ) ) ) ; addBinaryClause ( s , not ( lits . get ( i ) ) , seqAuxiliary . get ( i ) ) ; } else if ( i == lits . size ( ) - 1 ) { addBinaryClause ( s , lits . get ( i ) , seqAuxiliary . get ( i - 1 ) ) ; addBinaryClause ( s , not ( lits . get ( i ) ) , not ( seqAuxiliary . get ( i - 1 ) ) ) ; } else { addBinaryClause ( s , not ( seqAuxiliary . get ( i - 1 ) ) , seqAuxiliary . get ( i ) ) ; addTernaryClause ( s , lits . get ( i ) , not ( seqAuxiliary . get ( i ) ) , seqAuxiliary . get ( i - 1 ) ) ; addBinaryClause ( s , not ( lits . get ( i ) ) , seqAuxiliary . get ( i ) ) ; addBinaryClause ( s , not ( lits . get ( i ) ) , not ( seqAuxiliary . get ( i - 1 ) ) ) ; } } } }
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 .