repo stringlengths 7 58 | path stringlengths 12 218 | func_name stringlengths 3 140 | original_string stringlengths 73 34.1k | language stringclasses 1
value | code stringlengths 73 34.1k | code_tokens list | docstring stringlengths 3 16k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 105 339 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
jenkinsci/support-core-plugin | src/main/java/com/cloudbees/jenkins/support/util/WordReplacer.java | WordReplacer.replaceWords | 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;
}
// the same number of word to replace and replaces to use
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);
}
} | java | 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;
}
// the same number of word to replace and replaces to use
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);
}
} | [
"private",
"static",
"void",
"replaceWords",
"(",
"StringBuilder",
"input",
",",
"String",
"[",
"]",
"words",
",",
"String",
"[",
"]",
"replaces",
",",
"boolean",
"ignoreCase",
")",
"{",
"if",
"(",
"input",
"==",
"null",
"||",
"input",
".",
"length",
"("... | To avoid repeat this code above | [
"To",
"avoid",
"repeat",
"this",
"code",
"above"
] | bcbe1dfd5bf48ac89903645cd48ed897c1a04688 | https://github.com/jenkinsci/support-core-plugin/blob/bcbe1dfd5bf48ac89903645cd48ed897c1a04688/src/main/java/com/cloudbees/jenkins/support/util/WordReplacer.java#L55-L69 | train |
spring-projects/spring-credhub | spring-credhub-cloud-connector/src/main/java/org/springframework/credhub/cloud/CredHubInterpolationServiceDataPostProcessor.java | CredHubInterpolationServiceDataPostProcessor.connectorsToCredHub | private ServicesData connectorsToCredHub(CloudFoundryRawServiceData rawServiceData) {
ServicesData servicesData = new ServicesData();
servicesData.putAll(rawServiceData);
return servicesData;
} | java | private ServicesData connectorsToCredHub(CloudFoundryRawServiceData rawServiceData) {
ServicesData servicesData = new ServicesData();
servicesData.putAll(rawServiceData);
return servicesData;
} | [
"private",
"ServicesData",
"connectorsToCredHub",
"(",
"CloudFoundryRawServiceData",
"rawServiceData",
")",
"{",
"ServicesData",
"servicesData",
"=",
"new",
"ServicesData",
"(",
")",
";",
"servicesData",
".",
"putAll",
"(",
"rawServiceData",
")",
";",
"return",
"servi... | Convert from the Spring Cloud Connectors service data structure to the Spring
Credhub data structure.
@param rawServiceData the Spring Cloud Connectors data structure
@return the equivalent Spring CredHub data structure | [
"Convert",
"from",
"the",
"Spring",
"Cloud",
"Connectors",
"service",
"data",
"structure",
"to",
"the",
"Spring",
"Credhub",
"data",
"structure",
"."
] | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-cloud-connector/src/main/java/org/springframework/credhub/cloud/CredHubInterpolationServiceDataPostProcessor.java#L117-L121 | train |
spring-projects/spring-credhub | spring-credhub-cloud-connector/src/main/java/org/springframework/credhub/cloud/CredHubInterpolationServiceDataPostProcessor.java | CredHubInterpolationServiceDataPostProcessor.credHubToConnectors | private CloudFoundryRawServiceData credHubToConnectors(
ServicesData interpolatedData) {
CloudFoundryRawServiceData rawServicesData = new CloudFoundryRawServiceData();
rawServicesData.putAll(interpolatedData);
return rawServicesData;
} | java | private CloudFoundryRawServiceData credHubToConnectors(
ServicesData interpolatedData) {
CloudFoundryRawServiceData rawServicesData = new CloudFoundryRawServiceData();
rawServicesData.putAll(interpolatedData);
return rawServicesData;
} | [
"private",
"CloudFoundryRawServiceData",
"credHubToConnectors",
"(",
"ServicesData",
"interpolatedData",
")",
"{",
"CloudFoundryRawServiceData",
"rawServicesData",
"=",
"new",
"CloudFoundryRawServiceData",
"(",
")",
";",
"rawServicesData",
".",
"putAll",
"(",
"interpolatedDat... | Convert from the Spring Credhub service data structure to the Spring Cloud
Connectors data structure.
@param interpolatedData the Spring CredHub data structure
@return the equivalent Spring Cloud Connectors data structure | [
"Convert",
"from",
"the",
"Spring",
"Credhub",
"service",
"data",
"structure",
"to",
"the",
"Spring",
"Cloud",
"Connectors",
"data",
"structure",
"."
] | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-cloud-connector/src/main/java/org/springframework/credhub/cloud/CredHubInterpolationServiceDataPostProcessor.java#L130-L135 | train |
spring-projects/spring-credhub | spring-credhub-core/src/main/java/org/springframework/credhub/core/ExceptionUtils.java | ExceptionUtils.throwExceptionOnError | public static void throwExceptionOnError(ResponseEntity<?> response) {
if (!response.getStatusCode().equals(HttpStatus.OK)) {
throw new CredHubException(response.getStatusCode());
}
} | java | public static void throwExceptionOnError(ResponseEntity<?> response) {
if (!response.getStatusCode().equals(HttpStatus.OK)) {
throw new CredHubException(response.getStatusCode());
}
} | [
"public",
"static",
"void",
"throwExceptionOnError",
"(",
"ResponseEntity",
"<",
"?",
">",
"response",
")",
"{",
"if",
"(",
"!",
"response",
".",
"getStatusCode",
"(",
")",
".",
"equals",
"(",
"HttpStatus",
".",
"OK",
")",
")",
"{",
"throw",
"new",
"Cred... | Helper method to throw an appropriate exception if a request to CredHub
returns with an error code.
@param response a {@link ResponseEntity} returned from {@link RestTemplate} | [
"Helper",
"method",
"to",
"throw",
"an",
"appropriate",
"exception",
"if",
"a",
"request",
"to",
"CredHub",
"returns",
"with",
"an",
"error",
"code",
"."
] | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-core/src/main/java/org/springframework/credhub/core/ExceptionUtils.java#L33-L37 | train |
spring-projects/spring-credhub | spring-credhub-core/src/main/java/org/springframework/credhub/core/ExceptionUtils.java | ExceptionUtils.buildError | public static Mono<Throwable> buildError(ClientResponse response) {
return Mono.error(new CredHubException(response.statusCode()));
} | java | public static Mono<Throwable> buildError(ClientResponse response) {
return Mono.error(new CredHubException(response.statusCode()));
} | [
"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.
@return the generated error
@param response a {@link ClientResponse} returned from {@link WebClient} | [
"Helper",
"method",
"to",
"return",
"an",
"appropriate",
"error",
"if",
"a",
"request",
"to",
"CredHub",
"returns",
"with",
"an",
"error",
"code",
"."
] | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-core/src/main/java/org/springframework/credhub/core/ExceptionUtils.java#L46-L48 | train |
spring-projects/spring-credhub | spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java | Actor.app | public static Actor app(String appId) {
Assert.notNull(appId, "appId must not be null");
return new Actor(APP, appId);
} | java | public static Actor app(String appId) {
Assert.notNull(appId, "appId must not be null");
return new Actor(APP, appId);
} | [
"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.
@param appId the Cloud Foundry application GUID
@return the created {@literal Actor} | [
"Create",
"an",
"application",
"identifier",
".",
"An",
"application",
"is",
"identified",
"by",
"a",
"GUID",
"generated",
"by",
"Cloud",
"Foundry",
"when",
"the",
"application",
"is",
"created",
"."
] | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java#L58-L61 | train |
spring-projects/spring-credhub | spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java | Actor.user | public static Actor user(String userId) {
Assert.notNull(userId, "userId must not be null");
return new Actor(USER, userId);
} | java | public static Actor user(String userId) {
Assert.notNull(userId, "userId must not be null");
return new Actor(USER, userId);
} | [
"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.
@param userId the UAA user GUID
@return the created {@literal Actor} | [
"Create",
"a",
"user",
"identifier",
".",
"A",
"user",
"is",
"identified",
"by",
"a",
"GUID",
"generated",
"by",
"UAA",
"when",
"a",
"user",
"account",
"is",
"created",
"."
] | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java#L70-L73 | train |
spring-projects/spring-credhub | spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java | Actor.user | 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);
} | java | 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);
} | [
"public",
"static",
"Actor",
"user",
"(",
"String",
"zoneId",
",",
"String",
"userId",
")",
"{",
"Assert",
".",
"notNull",
"(",
"zoneId",
",",
"\"zoneId must not be null\"",
")",
";",
"Assert",
".",
"notNull",
"(",
"userId",
",",
"\"userId must not be null\"",
... | 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.
@param zoneId the UAA identity zone ID
@param userId the UAA user GUID
@return the created {@literal Actor} | [
"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",... | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java#L83-L87 | train |
spring-projects/spring-credhub | spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java | Actor.client | public static Actor client(String clientId) {
Assert.notNull(clientId, "clientId must not be null");
return new Actor(OAUTH_CLIENT, clientId);
} | java | public static Actor client(String clientId) {
Assert.notNull(clientId, "clientId must not be null");
return new Actor(OAUTH_CLIENT, clientId);
} | [
"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.
@param clientId the UAA client ID
@return the created {@literal Actor} | [
"Create",
"an",
"OAuth2",
"client",
"identifier",
".",
"A",
"client",
"identified",
"by",
"user",
"-",
"provided",
"identifier",
"."
] | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java#L95-L98 | train |
spring-projects/spring-credhub | spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java | Actor.client | 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);
} | java | 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);
} | [
"public",
"static",
"Actor",
"client",
"(",
"String",
"zoneId",
",",
"String",
"clientId",
")",
"{",
"Assert",
".",
"notNull",
"(",
"zoneId",
",",
"\"zoneId must not be null\"",
")",
";",
"Assert",
".",
"notNull",
"(",
"clientId",
",",
"\"clientId must not be nu... | Create an OAuth2 client identifier. A client identified by user-provided identifier
and the ID of the identity zone the client was created in.
@param zoneId the UAA identity zone ID
@param clientId the UAA client ID
@return the created {@literal Actor} | [
"Create",
"an",
"OAuth2",
"client",
"identifier",
".",
"A",
"client",
"identified",
"by",
"user",
"-",
"provided",
"identifier",
"and",
"the",
"ID",
"of",
"the",
"identity",
"zone",
"the",
"client",
"was",
"created",
"in",
"."
] | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Actor.java#L108-L112 | train |
spring-projects/spring-credhub | spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Permission.java | Permission.getOperationsAsString | @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;
} | java | @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;
} | [
"@",
"JsonGetter",
"(",
"\"operations\"",
")",
"private",
"List",
"<",
"String",
">",
"getOperationsAsString",
"(",
")",
"{",
"if",
"(",
"operations",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"List",
"<",
"String",
">",
"operationValues",
"=",
... | Get the set of operations that the actor will be allowed to perform on
the credential.
@return the operations | [
"Get",
"the",
"set",
"of",
"operations",
"that",
"the",
"actor",
"will",
"be",
"allowed",
"to",
"perform",
"on",
"the",
"credential",
"."
] | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-core/src/main/java/org/springframework/credhub/support/permissions/Permission.java#L94-L105 | train |
spring-projects/spring-credhub | spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubOAuth2RequestInterceptor.java | CredHubOAuth2RequestInterceptor.intercept | @Override
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);
} | java | @Override
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);
} | [
"@",
"Override",
"public",
"ClientHttpResponse",
"intercept",
"(",
"HttpRequest",
"request",
",",
"byte",
"[",
"]",
"body",
",",
"ClientHttpRequestExecution",
"execution",
")",
"throws",
"IOException",
"{",
"HttpRequestWrapper",
"requestWrapper",
"=",
"new",
"HttpRequ... | Add an OAuth2 bearer token header to each request.
{@inheritDoc} | [
"Add",
"an",
"OAuth2",
"bearer",
"token",
"header",
"to",
"each",
"request",
"."
] | 4d82cfa60d6c04e707ff32d78bc5d80cff4e132e | https://github.com/spring-projects/spring-credhub/blob/4d82cfa60d6c04e707ff32d78bc5d80cff4e132e/spring-credhub-core/src/main/java/org/springframework/credhub/core/CredHubOAuth2RequestInterceptor.java#L70-L79 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/SimpleFileDownloader.java | SimpleFileDownloader.copyLocalFile | 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);
}
} | java | 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);
}
} | [
"protected",
"Path",
"copyLocalFile",
"(",
"URL",
"fileUrl",
")",
"throws",
"IOException",
",",
"PluginException",
"{",
"Path",
"destination",
"=",
"Files",
".",
"createTempDirectory",
"(",
"\"pf4j-update-downloader\"",
")",
";",
"destination",
".",
"toFile",
"(",
... | Efficient copy of file in case of local file system.
@param fileUrl source file
@return path of target file
@throws IOException if problems during copy
@throws PluginException in case of other problems | [
"Efficient",
"copy",
"of",
"file",
"in",
"case",
"of",
"local",
"file",
"system",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/SimpleFileDownloader.java#L75-L90 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/SimpleFileDownloader.java | SimpleFileDownloader.downloadFileHttp | 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);
// set up the URL connection
URLConnection connection = fileUrl.openConnection();
// connect to the remote site (may takes some time)
connection.connect();
// check for http authorization
HttpURLConnection httpConnection = (HttpURLConnection) connection;
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new ConnectException("HTTP Authorization failure");
}
// try to get the server-specified last-modified date of this artifact
long lastModified = httpConnection.getHeaderFieldDate("Last-Modified", System.currentTimeMillis());
// try to get the input stream (three times)
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 + "'");
}
// reade from remote resource and write to the local 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;
} | java | 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);
// set up the URL connection
URLConnection connection = fileUrl.openConnection();
// connect to the remote site (may takes some time)
connection.connect();
// check for http authorization
HttpURLConnection httpConnection = (HttpURLConnection) connection;
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new ConnectException("HTTP Authorization failure");
}
// try to get the server-specified last-modified date of this artifact
long lastModified = httpConnection.getHeaderFieldDate("Last-Modified", System.currentTimeMillis());
// try to get the input stream (three times)
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 + "'");
}
// reade from remote resource and write to the local 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;
} | [
"protected",
"Path",
"downloadFileHttp",
"(",
"URL",
"fileUrl",
")",
"throws",
"IOException",
",",
"PluginException",
"{",
"Path",
"destination",
"=",
"Files",
".",
"createTempDirectory",
"(",
"\"pf4j-update-downloader\"",
")",
";",
"destination",
".",
"toFile",
"("... | Downloads file from HTTP or FTP.
@param fileUrl source file
@return path of downloaded file
@throws IOException if IO problems
@throws PluginException if validation fails or any other problems | [
"Downloads",
"file",
"from",
"HTTP",
"or",
"FTP",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/SimpleFileDownloader.java#L100-L151 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.getUpdates | 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;
} | java | 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;
} | [
"public",
"List",
"<",
"PluginInfo",
">",
"getUpdates",
"(",
")",
"{",
"List",
"<",
"PluginInfo",
">",
"updates",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"PluginWrapper",
"installed",
":",
"pluginManager",
".",
"getPlugins",
"(",
")",
"... | Return a list of plugins that are newer versions of already installed plugins.
@return list of plugins that have updates | [
"Return",
"a",
"list",
"of",
"plugins",
"that",
"are",
"newer",
"versions",
"of",
"already",
"installed",
"plugins",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L101-L111 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.getPlugins | public List<PluginInfo> getPlugins() {
List<PluginInfo> list = new ArrayList<>(getPluginsMap().values());
Collections.sort(list);
return list;
} | java | public List<PluginInfo> getPlugins() {
List<PluginInfo> list = new ArrayList<>(getPluginsMap().values());
Collections.sort(list);
return list;
} | [
"public",
"List",
"<",
"PluginInfo",
">",
"getPlugins",
"(",
")",
"{",
"List",
"<",
"PluginInfo",
">",
"list",
"=",
"new",
"ArrayList",
"<>",
"(",
"getPluginsMap",
"(",
")",
".",
"values",
"(",
")",
")",
";",
"Collections",
".",
"sort",
"(",
"list",
... | Get the list of plugins from all repos.
@return List of plugin info | [
"Get",
"the",
"list",
"of",
"plugins",
"from",
"all",
"repos",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L127-L132 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.getPluginsMap | public Map<String, PluginInfo> getPluginsMap() {
Map<String, PluginInfo> pluginsMap = new HashMap<>();
for (UpdateRepository repository : getRepositories()) {
pluginsMap.putAll(repository.getPlugins());
}
return pluginsMap;
} | java | public Map<String, PluginInfo> getPluginsMap() {
Map<String, PluginInfo> pluginsMap = new HashMap<>();
for (UpdateRepository repository : getRepositories()) {
pluginsMap.putAll(repository.getPlugins());
}
return pluginsMap;
} | [
"public",
"Map",
"<",
"String",
",",
"PluginInfo",
">",
"getPluginsMap",
"(",
")",
"{",
"Map",
"<",
"String",
",",
"PluginInfo",
">",
"pluginsMap",
"=",
"new",
"HashMap",
"<>",
"(",
")",
";",
"for",
"(",
"UpdateRepository",
"repository",
":",
"getRepositor... | Get a map of all plugins from all repos where key is plugin id.
@return List of plugin info | [
"Get",
"a",
"map",
"of",
"all",
"plugins",
"from",
"all",
"repos",
"where",
"key",
"is",
"plugin",
"id",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L139-L146 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.addRepository | 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);
} | java | 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);
} | [
"public",
"void",
"addRepository",
"(",
"UpdateRepository",
"newRepo",
")",
"{",
"for",
"(",
"UpdateRepository",
"ur",
":",
"repositories",
")",
"{",
"if",
"(",
"ur",
".",
"getId",
"(",
")",
".",
"equals",
"(",
"newRepo",
".",
"getId",
"(",
")",
")",
"... | Add a repo that was created by client.
@param newRepo the new UpdateRepository to add to the list | [
"Add",
"a",
"repo",
"that",
"was",
"created",
"by",
"client",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L186-L194 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.removeRepository | 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");
} | java | 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");
} | [
"public",
"void",
"removeRepository",
"(",
"String",
"id",
")",
"{",
"for",
"(",
"UpdateRepository",
"repo",
":",
"getRepositories",
"(",
")",
")",
"{",
"if",
"(",
"id",
".",
"equals",
"(",
"repo",
".",
"getId",
"(",
")",
")",
")",
"{",
"repositories",... | Remove a repository by id.
@param id of repository to remove | [
"Remove",
"a",
"repository",
"by",
"id",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L201-L209 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.refresh | public synchronized void refresh() {
if (repositoriesJson != null) {
initRepositoriesFromJson();
}
for (UpdateRepository updateRepository : repositories) {
updateRepository.refresh();
}
lastPluginRelease.clear();
} | java | public synchronized void refresh() {
if (repositoriesJson != null) {
initRepositoriesFromJson();
}
for (UpdateRepository updateRepository : repositories) {
updateRepository.refresh();
}
lastPluginRelease.clear();
} | [
"public",
"synchronized",
"void",
"refresh",
"(",
")",
"{",
"if",
"(",
"repositoriesJson",
"!=",
"null",
")",
"{",
"initRepositoriesFromJson",
"(",
")",
";",
"}",
"for",
"(",
"UpdateRepository",
"updateRepository",
":",
"repositories",
")",
"{",
"updateRepositor... | Refreshes all repositories, so they are forced to refresh list of plugins. | [
"Refreshes",
"all",
"repositories",
"so",
"they",
"are",
"forced",
"to",
"refresh",
"list",
"of",
"plugins",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L214-L222 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.installPlugin | public synchronized boolean installPlugin(String id, String version) throws PluginException {
// Download to temporary location
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);
} | java | public synchronized boolean installPlugin(String id, String version) throws PluginException {
// Download to temporary location
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);
} | [
"public",
"synchronized",
"boolean",
"installPlugin",
"(",
"String",
"id",
",",
"String",
"version",
")",
"throws",
"PluginException",
"{",
"// Download to temporary location",
"Path",
"downloaded",
"=",
"downloadPlugin",
"(",
"id",
",",
"version",
")",
";",
"Path",... | Installs a plugin by id and version.
@param id the id of plugin to install
@param version the version of plugin to install, on SemVer format, or null for latest
@return true if installation successful and plugin started
@exception PluginException if plugin does not exist in repos or problems during | [
"Installs",
"a",
"plugin",
"by",
"id",
"and",
"version",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L232-L248 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.getFileVerifier | protected FileVerifier getFileVerifier(String pluginId) {
for (UpdateRepository ur : repositories) {
if (ur.getPlugin(pluginId) != null && ur.getFileVerfier() != null) {
return ur.getFileVerfier();
}
}
return new CompoundVerifier();
} | java | protected FileVerifier getFileVerifier(String pluginId) {
for (UpdateRepository ur : repositories) {
if (ur.getPlugin(pluginId) != null && ur.getFileVerfier() != null) {
return ur.getFileVerfier();
}
}
return new CompoundVerifier();
} | [
"protected",
"FileVerifier",
"getFileVerifier",
"(",
"String",
"pluginId",
")",
"{",
"for",
"(",
"UpdateRepository",
"ur",
":",
"repositories",
")",
"{",
"if",
"(",
"ur",
".",
"getPlugin",
"(",
"pluginId",
")",
"!=",
"null",
"&&",
"ur",
".",
"getFileVerfier"... | 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
@param pluginId the plugin we wish to download
@return FileVerifier instance | [
"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"
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L293-L301 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.findReleaseForPlugin | 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);
} | java | 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);
} | [
"protected",
"PluginRelease",
"findReleaseForPlugin",
"(",
"String",
"id",
",",
"String",
"version",
")",
"throws",
"PluginException",
"{",
"PluginInfo",
"pluginInfo",
"=",
"getPluginsMap",
"(",
")",
".",
"get",
"(",
"id",
")",
";",
"if",
"(",
"pluginInfo",
"=... | Resolves Release from id and version.
@param id of plugin
@param version of plugin or null to locate latest version
@return PluginRelease for downloading
@throws PluginException if id or version does not exist | [
"Resolves",
"Release",
"from",
"id",
"and",
"version",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L311-L329 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.getLastPluginRelease | 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);
} | java | 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);
} | [
"public",
"PluginRelease",
"getLastPluginRelease",
"(",
"String",
"id",
")",
"{",
"PluginInfo",
"pluginInfo",
"=",
"getPluginsMap",
"(",
")",
".",
"get",
"(",
"id",
")",
";",
"if",
"(",
"pluginInfo",
"==",
"null",
")",
"{",
"return",
"null",
";",
"}",
"i... | Returns the last release version of this plugin for given system version, regardless of release date.
@return PluginRelease which has the highest version number | [
"Returns",
"the",
"last",
"release",
"version",
"of",
"this",
"plugin",
"for",
"given",
"system",
"version",
"regardless",
"of",
"release",
"date",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L384-L403 | train |
pf4j/pf4j-update | src/main/java/org/pf4j/update/UpdateManager.java | UpdateManager.hasPluginUpdate | 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;
} | java | 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;
} | [
"public",
"boolean",
"hasPluginUpdate",
"(",
"String",
"id",
")",
"{",
"PluginInfo",
"pluginInfo",
"=",
"getPluginsMap",
"(",
")",
".",
"get",
"(",
"id",
")",
";",
"if",
"(",
"pluginInfo",
"==",
"null",
")",
"{",
"return",
"false",
";",
"}",
"String",
... | Finds whether the newer version of the plugin.
@return true if there is a newer version available which is compatible with system | [
"Finds",
"whether",
"the",
"newer",
"version",
"of",
"the",
"plugin",
"."
] | 80cf04b8f2790808d0cf9dff3602dc5d730ac979 | https://github.com/pf4j/pf4j-update/blob/80cf04b8f2790808d0cf9dff3602dc5d730ac979/src/main/java/org/pf4j/update/UpdateManager.java#L410-L420 | train |
logic-ng/LogicNG | src/main/java/org/logicng/bdds/orderings/ForceOrdering.java | ForceOrdering.force | 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);
} | java | 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);
} | [
"private",
"List",
"<",
"Variable",
">",
"force",
"(",
"final",
"Formula",
"formula",
",",
"final",
"Hypergraph",
"<",
"Variable",
">",
"hypergraph",
",",
"final",
"Map",
"<",
"Variable",
",",
"HypergraphNode",
"<",
"Variable",
">",
">",
"nodes",
")",
"{",... | Executes the main FORCE algorithm.
@param formula the CNF formula for the ordering
@param hypergraph the hypergraph for this formula
@param nodes the variable to hypergraph node mapping
@return the variable ordering according to the FORCE algorithm | [
"Executes",
"the",
"main",
"FORCE",
"algorithm",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/bdds/orderings/ForceOrdering.java#L83-L99 | train |
logic-ng/LogicNG | src/main/java/org/logicng/bdds/orderings/ForceOrdering.java | ForceOrdering.createInitialOrdering | 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;
} | java | 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;
} | [
"private",
"LinkedHashMap",
"<",
"HypergraphNode",
"<",
"Variable",
">",
",",
"Integer",
">",
"createInitialOrdering",
"(",
"final",
"Formula",
"formula",
",",
"final",
"Map",
"<",
"Variable",
",",
"HypergraphNode",
"<",
"Variable",
">",
">",
"nodes",
")",
"{"... | Creates an initial ordering for the variables based on a DFS.
@param formula the CNF formula
@param nodes the variable to hypergraph node mapping
@return the initial variable ordering | [
"Creates",
"an",
"initial",
"ordering",
"for",
"the",
"variables",
"based",
"on",
"a",
"DFS",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/bdds/orderings/ForceOrdering.java#L107-L113 | train |
logic-ng/LogicNG | src/main/java/org/logicng/bdds/orderings/ForceOrdering.java | ForceOrdering.orderingFromTentativeNewLocations | 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;
}
/**
* The abortion criteria for the FORCE algorithm.
* @param lastOrdering the ordering of the last step
* @param currentOrdering the ordering of the current step
* @return {@code true} if the algorithm should proceed, {@code false} if it should stop
*/
private boolean shouldProceed(final Map<HypergraphNode<Variable>, Integer> lastOrdering, final Map<HypergraphNode<Variable>, Integer> currentOrdering) {
return !lastOrdering.equals(currentOrdering);
} | java | 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;
}
/**
* The abortion criteria for the FORCE algorithm.
* @param lastOrdering the ordering of the last step
* @param currentOrdering the ordering of the current step
* @return {@code true} if the algorithm should proceed, {@code false} if it should stop
*/
private boolean shouldProceed(final Map<HypergraphNode<Variable>, Integer> lastOrdering, final Map<HypergraphNode<Variable>, Integer> currentOrdering) {
return !lastOrdering.equals(currentOrdering);
} | [
"private",
"LinkedHashMap",
"<",
"HypergraphNode",
"<",
"Variable",
">",
",",
"Integer",
">",
"orderingFromTentativeNewLocations",
"(",
"final",
"LinkedHashMap",
"<",
"HypergraphNode",
"<",
"Variable",
">",
",",
"Double",
">",
"newLocations",
")",
"{",
"final",
"L... | Generates a new integer ordering from tentative new locations of nodes with the double weighting.
@param newLocations the tentative new locations
@return the new integer ordering | [
"Generates",
"a",
"new",
"integer",
"ordering",
"from",
"tentative",
"new",
"locations",
"of",
"nodes",
"with",
"the",
"double",
"weighting",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/bdds/orderings/ForceOrdering.java#L120-L138 | train |
logic-ng/LogicNG | src/main/java/org/logicng/graphs/datastructures/Hypergraph.java | Hypergraph.addEdge | public void addEdge(final Collection<HypergraphNode<T>> nodes) {
final HypergraphEdge<T> edge = new HypergraphEdge<>(nodes);
this.nodes.addAll(nodes);
this.edges.add(edge);
} | java | public void addEdge(final Collection<HypergraphNode<T>> nodes) {
final HypergraphEdge<T> edge = new HypergraphEdge<>(nodes);
this.nodes.addAll(nodes);
this.edges.add(edge);
} | [
"public",
"void",
"addEdge",
"(",
"final",
"Collection",
"<",
"HypergraphNode",
"<",
"T",
">",
">",
"nodes",
")",
"{",
"final",
"HypergraphEdge",
"<",
"T",
">",
"edge",
"=",
"new",
"HypergraphEdge",
"<>",
"(",
"nodes",
")",
";",
"this",
".",
"nodes",
"... | Adds an edges to the hypergraph. The edge is represented by its connected nodes.
@param nodes the nodes of the edge | [
"Adds",
"an",
"edges",
"to",
"the",
"hypergraph",
".",
"The",
"edge",
"is",
"represented",
"by",
"its",
"connected",
"nodes",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/graphs/datastructures/Hypergraph.java#L91-L95 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/printer/SortedStringRepresentation.java | SortedStringRepresentation.naryOperator | @Override
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();
} | java | @Override
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();
} | [
"@",
"Override",
"protected",
"String",
"naryOperator",
"(",
"final",
"NAryOperator",
"operator",
",",
"final",
"String",
"opString",
")",
"{",
"final",
"List",
"<",
"Formula",
">",
"operands",
"=",
"new",
"ArrayList",
"<>",
"(",
")",
";",
"for",
"(",
"fin... | Returns the sorted string representation of an n-ary operator.
@param operator the n-ary operator
@param opString the operator string
@return the string representation | [
"Returns",
"the",
"sorted",
"string",
"representation",
"of",
"an",
"n",
"-",
"ary",
"operator",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/printer/SortedStringRepresentation.java#L142-L165 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/printer/SortedStringRepresentation.java | SortedStringRepresentation.pbLhs | @Override
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();
} | java | @Override
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();
} | [
"@",
"Override",
"protected",
"String",
"pbLhs",
"(",
"final",
"Literal",
"[",
"]",
"operands",
",",
"final",
"int",
"[",
"]",
"coefficients",
")",
"{",
"assert",
"operands",
".",
"length",
"==",
"coefficients",
".",
"length",
";",
"final",
"List",
"<",
... | Returns the sorted string representation of the left-hand side of a pseudo-Boolean constraint.
@param operands the literals of the constraint
@param coefficients the coefficients of the constraint
@return the sorted string representation | [
"Returns",
"the",
"sorted",
"string",
"representation",
"of",
"the",
"left",
"-",
"hand",
"side",
"of",
"a",
"pseudo",
"-",
"Boolean",
"constraint",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/printer/SortedStringRepresentation.java#L174-L211 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/printer/SortedStringRepresentation.java | SortedStringRepresentation.sortedEquivalence | 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);
} | java | 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);
} | [
"private",
"String",
"sortedEquivalence",
"(",
"final",
"Equivalence",
"equivalence",
")",
"{",
"final",
"Formula",
"right",
";",
"final",
"Formula",
"left",
";",
"if",
"(",
"this",
".",
"comparator",
".",
"compare",
"(",
"equivalence",
".",
"left",
"(",
")"... | Returns the string representation of an equivalence.
@param equivalence the equivalence
@return the string representation | [
"Returns",
"the",
"string",
"representation",
"of",
"an",
"equivalence",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/printer/SortedStringRepresentation.java#L219-L232 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/datastructures/LNGHeap.java | LNGHeap.insert | 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));
} | java | 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));
} | [
"public",
"void",
"insert",
"(",
"int",
"n",
")",
"{",
"this",
".",
"indices",
".",
"growTo",
"(",
"n",
"+",
"1",
",",
"-",
"1",
")",
";",
"assert",
"!",
"this",
".",
"inHeap",
"(",
"n",
")",
";",
"this",
".",
"indices",
".",
"set",
"(",
"n",... | Inserts a given element in the heap.
@param n the element | [
"Inserts",
"a",
"given",
"element",
"in",
"the",
"heap",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/datastructures/LNGHeap.java#L147-L153 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/datastructures/LNGHeap.java | LNGHeap.removeMin | 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;
} | java | 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;
} | [
"public",
"int",
"removeMin",
"(",
")",
"{",
"int",
"x",
"=",
"this",
".",
"heap",
".",
"get",
"(",
"0",
")",
";",
"this",
".",
"heap",
".",
"set",
"(",
"0",
",",
"this",
".",
"heap",
".",
"back",
"(",
")",
")",
";",
"this",
".",
"indices",
... | Removes the minimal element of the heap.
@return the minimal element of the heap | [
"Removes",
"the",
"minimal",
"element",
"of",
"the",
"heap",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/datastructures/LNGHeap.java#L159-L168 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/datastructures/LNGHeap.java | LNGHeap.remove | 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();
} | java | 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();
} | [
"public",
"void",
"remove",
"(",
"int",
"n",
")",
"{",
"assert",
"this",
".",
"inHeap",
"(",
"n",
")",
";",
"int",
"kPos",
"=",
"this",
".",
"indices",
".",
"get",
"(",
"n",
")",
";",
"this",
".",
"indices",
".",
"set",
"(",
"n",
",",
"-",
"1... | Removes a given element of the heap.
@param n the element | [
"Removes",
"a",
"given",
"element",
"of",
"the",
"heap",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/datastructures/LNGHeap.java#L174-L185 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/datastructures/LNGHeap.java | LNGHeap.build | 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);
} | java | 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);
} | [
"public",
"void",
"build",
"(",
"final",
"LNGIntVector",
"ns",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"heap",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"this",
".",
"indices",
".",
"set",
"(",
"this",
".",
"... | Rebuilds the heap from a given vector of elements.
@param ns the vector of elements | [
"Rebuilds",
"the",
"heap",
"from",
"a",
"given",
"vector",
"of",
"elements",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/datastructures/LNGHeap.java#L191-L201 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/datastructures/LNGHeap.java | LNGHeap.clear | public void clear() {
for (int i = 0; i < this.heap.size(); i++)
this.indices.set(this.heap.get(i), -1);
this.heap.clear();
} | java | public void clear() {
for (int i = 0; i < this.heap.size(); i++)
this.indices.set(this.heap.get(i), -1);
this.heap.clear();
} | [
"public",
"void",
"clear",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"heap",
".",
"size",
"(",
")",
";",
"i",
"++",
")",
"this",
".",
"indices",
".",
"set",
"(",
"this",
".",
"heap",
".",
"get",
"(",
"i",
... | Clears the heap. | [
"Clears",
"the",
"heap",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/datastructures/LNGHeap.java#L206-L210 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/datastructures/LNGHeap.java | LNGHeap.percolateUp | 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);
} | java | 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);
} | [
"private",
"void",
"percolateUp",
"(",
"int",
"pos",
")",
"{",
"int",
"x",
"=",
"this",
".",
"heap",
".",
"get",
"(",
"pos",
")",
";",
"int",
"p",
"=",
"parent",
"(",
"pos",
")",
";",
"int",
"j",
"=",
"pos",
";",
"while",
"(",
"j",
"!=",
"0",... | Bubbles a element at a given position up.
@param pos the position | [
"Bubbles",
"a",
"element",
"at",
"a",
"given",
"position",
"up",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/datastructures/LNGHeap.java#L216-L228 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/datastructures/LNGHeap.java | LNGHeap.percolateDown | 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);
} | java | 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);
} | [
"private",
"void",
"percolateDown",
"(",
"int",
"pos",
")",
"{",
"int",
"p",
"=",
"pos",
";",
"int",
"y",
"=",
"this",
".",
"heap",
".",
"get",
"(",
"p",
")",
";",
"while",
"(",
"left",
"(",
"p",
")",
"<",
"this",
".",
"heap",
".",
"size",
"(... | Bubbles a element at a given position down.
@param pos the position | [
"Bubbles",
"a",
"element",
"at",
"a",
"given",
"position",
"down",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/datastructures/LNGHeap.java#L234-L247 | train |
logic-ng/LogicNG | src/main/java/org/logicng/datastructures/EncodingResult.java | EncodingResult.resultForMiniSat | public static EncodingResult resultForMiniSat(final FormulaFactory f, final MiniSat miniSat) {
return new EncodingResult(f, miniSat, null);
} | java | public static EncodingResult resultForMiniSat(final FormulaFactory f, final MiniSat miniSat) {
return new EncodingResult(f, miniSat, null);
} | [
"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.
@param f the formula factory
@param miniSat the solver
@return the result | [
"Constructs",
"a",
"new",
"result",
"which",
"adds",
"the",
"result",
"directly",
"to",
"a",
"given",
"MiniSat",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/datastructures/EncodingResult.java#L88-L90 | train |
logic-ng/LogicNG | src/main/java/org/logicng/datastructures/EncodingResult.java | EncodingResult.resultForCleaneLing | public static EncodingResult resultForCleaneLing(final FormulaFactory f, final CleaneLing cleaneLing) {
return new EncodingResult(f, null, cleaneLing);
} | java | public static EncodingResult resultForCleaneLing(final FormulaFactory f, final CleaneLing cleaneLing) {
return new EncodingResult(f, null, cleaneLing);
} | [
"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.
@param f the formula factory
@param cleaneLing the CleaneLing solver
@return the result | [
"Constructs",
"a",
"new",
"result",
"which",
"adds",
"the",
"result",
"directly",
"to",
"a",
"given",
"CleaneLing",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/datastructures/EncodingResult.java#L98-L100 | train |
logic-ng/LogicNG | src/main/java/org/logicng/datastructures/EncodingResult.java | EncodingResult.addClause | 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();
}
} | java | 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();
}
} | [
"public",
"void",
"addClause",
"(",
"final",
"Literal",
"...",
"literals",
")",
"{",
"if",
"(",
"this",
".",
"miniSat",
"==",
"null",
"&&",
"this",
".",
"cleaneLing",
"==",
"null",
")",
"this",
".",
"result",
".",
"add",
"(",
"this",
".",
"f",
".",
... | Adds a clause to the result
@param literals the literals of the clause | [
"Adds",
"a",
"clause",
"to",
"the",
"result"
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/datastructures/EncodingResult.java#L106-L137 | train |
logic-ng/LogicNG | src/main/java/org/logicng/datastructures/EncodingResult.java | EncodingResult.vec2clause | 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);
} | java | 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);
} | [
"private",
"Formula",
"vec2clause",
"(",
"final",
"LNGVector",
"<",
"Literal",
">",
"literals",
")",
"{",
"final",
"List",
"<",
"Literal",
">",
"lits",
"=",
"new",
"ArrayList",
"<>",
"(",
"literals",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"final"... | Returns a clause for a vector of literals.
@param literals the literals
@return the clause | [
"Returns",
"a",
"clause",
"for",
"a",
"vector",
"of",
"literals",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/datastructures/EncodingResult.java#L181-L186 | train |
logic-ng/LogicNG | src/main/java/org/logicng/datastructures/EncodingResult.java | EncodingResult.newVariable | 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);
} | java | 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);
} | [
"public",
"Variable",
"newVariable",
"(",
")",
"{",
"if",
"(",
"this",
".",
"miniSat",
"==",
"null",
"&&",
"this",
".",
"cleaneLing",
"==",
"null",
")",
"return",
"this",
".",
"f",
".",
"newCCVariable",
"(",
")",
";",
"else",
"if",
"(",
"this",
".",
... | Returns a new auxiliary variable.
@return a new auxiliary variable | [
"Returns",
"a",
"new",
"auxiliary",
"variable",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/datastructures/EncodingResult.java#L192-L202 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/MiniSat.java | MiniSat.miniSat | public static MiniSat miniSat(final FormulaFactory f) {
return new MiniSat(f, SolverStyle.MINISAT, new MiniSatConfig.Builder().build(), null);
} | java | public static MiniSat miniSat(final FormulaFactory f) {
return new MiniSat(f, SolverStyle.MINISAT, new MiniSatConfig.Builder().build(), null);
} | [
"public",
"static",
"MiniSat",
"miniSat",
"(",
"final",
"FormulaFactory",
"f",
")",
"{",
"return",
"new",
"MiniSat",
"(",
"f",
",",
"SolverStyle",
".",
"MINISAT",
",",
"new",
"MiniSatConfig",
".",
"Builder",
"(",
")",
".",
"build",
"(",
")",
",",
"null",... | Returns a new MiniSat solver.
@param f the formula factory
@return the solver | [
"Returns",
"a",
"new",
"MiniSat",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/MiniSat.java#L131-L133 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/MiniSat.java | MiniSat.miniSat | public static MiniSat miniSat(final FormulaFactory f, final MiniSatConfig config) {
return new MiniSat(f, SolverStyle.MINISAT, config, null);
} | java | public static MiniSat miniSat(final FormulaFactory f, final MiniSatConfig config) {
return new MiniSat(f, SolverStyle.MINISAT, config, null);
} | [
"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.
@param f the formula factory
@param config the configuration
@return the solver | [
"Returns",
"a",
"new",
"MiniSat",
"solver",
"with",
"a",
"given",
"configuration",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/MiniSat.java#L141-L143 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/MiniSat.java | MiniSat.glucose | public static MiniSat glucose(final FormulaFactory f) {
return new MiniSat(f, SolverStyle.GLUCOSE, new MiniSatConfig.Builder().build(), new GlucoseConfig.Builder().build());
} | java | public static MiniSat glucose(final FormulaFactory f) {
return new MiniSat(f, SolverStyle.GLUCOSE, new MiniSatConfig.Builder().build(), new GlucoseConfig.Builder().build());
} | [
"public",
"static",
"MiniSat",
"glucose",
"(",
"final",
"FormulaFactory",
"f",
")",
"{",
"return",
"new",
"MiniSat",
"(",
"f",
",",
"SolverStyle",
".",
"GLUCOSE",
",",
"new",
"MiniSatConfig",
".",
"Builder",
"(",
")",
".",
"build",
"(",
")",
",",
"new",
... | Returns a new Glucose solver.
@param f the formula factory
@return the solver | [
"Returns",
"a",
"new",
"Glucose",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/MiniSat.java#L150-L152 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/MiniSat.java | MiniSat.glucose | public static MiniSat glucose(final FormulaFactory f, final MiniSatConfig miniSatConfig,
final GlucoseConfig glucoseConfig) {
return new MiniSat(f, SolverStyle.GLUCOSE, miniSatConfig, glucoseConfig);
} | java | public static MiniSat glucose(final FormulaFactory f, final MiniSatConfig miniSatConfig,
final GlucoseConfig glucoseConfig) {
return new MiniSat(f, SolverStyle.GLUCOSE, miniSatConfig, glucoseConfig);
} | [
"public",
"static",
"MiniSat",
"glucose",
"(",
"final",
"FormulaFactory",
"f",
",",
"final",
"MiniSatConfig",
"miniSatConfig",
",",
"final",
"GlucoseConfig",
"glucoseConfig",
")",
"{",
"return",
"new",
"MiniSat",
"(",
"f",
",",
"SolverStyle",
".",
"GLUCOSE",
","... | Returns a new Glucose solver with a given configuration.
@param f the formula factory
@param miniSatConfig the MiniSat configuration
@param glucoseConfig the Glucose configuration
@return the solver | [
"Returns",
"a",
"new",
"Glucose",
"solver",
"with",
"a",
"given",
"configuration",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/MiniSat.java#L161-L164 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/MiniSat.java | MiniSat.miniCard | public static MiniSat miniCard(final FormulaFactory f) {
return new MiniSat(f, SolverStyle.MINICARD, new MiniSatConfig.Builder().build(), null);
} | java | public static MiniSat miniCard(final FormulaFactory f) {
return new MiniSat(f, SolverStyle.MINICARD, new MiniSatConfig.Builder().build(), null);
} | [
"public",
"static",
"MiniSat",
"miniCard",
"(",
"final",
"FormulaFactory",
"f",
")",
"{",
"return",
"new",
"MiniSat",
"(",
"f",
",",
"SolverStyle",
".",
"MINICARD",
",",
"new",
"MiniSatConfig",
".",
"Builder",
"(",
")",
".",
"build",
"(",
")",
",",
"null... | Returns a new MiniCard solver.
@param f the formula factory
@return the solver | [
"Returns",
"a",
"new",
"MiniCard",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/MiniSat.java#L171-L173 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/MiniSat.java | MiniSat.miniCard | public static MiniSat miniCard(final FormulaFactory f, final MiniSatConfig config) {
return new MiniSat(f, SolverStyle.MINICARD, config, null);
} | java | public static MiniSat miniCard(final FormulaFactory f, final MiniSatConfig config) {
return new MiniSat(f, SolverStyle.MINICARD, config, null);
} | [
"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.
@param f the formula factory
@param config the configuration
@return the solver | [
"Returns",
"a",
"new",
"MiniCard",
"solver",
"with",
"a",
"given",
"configuration",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/MiniSat.java#L181-L183 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/MiniSat.java | MiniSat.generateBlockingClause | 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;
} | java | 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;
} | [
"private",
"LNGIntVector",
"generateBlockingClause",
"(",
"final",
"LNGBooleanVector",
"modelFromSolver",
",",
"final",
"LNGIntVector",
"relevantVars",
")",
"{",
"final",
"LNGIntVector",
"blockingClause",
";",
"if",
"(",
"relevantVars",
"!=",
"null",
")",
"{",
"blocki... | Generates a blocking clause from a given model and a set of relevant variables.
@param modelFromSolver the current model for which the blocking clause should be generated
@param relevantVars the indices of the relevant variables. If {@code null} all variables are relevant.
@return the blocking clause for the given model and relevant variables | [
"Generates",
"a",
"blocking",
"clause",
"from",
"a",
"given",
"model",
"and",
"a",
"set",
"of",
"relevant",
"variables",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/MiniSat.java#L371-L390 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/MiniSat.java | MiniSat.generateClauseVector | 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;
} | java | 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;
} | [
"private",
"LNGIntVector",
"generateClauseVector",
"(",
"final",
"Collection",
"<",
"Literal",
">",
"literals",
")",
"{",
"final",
"LNGIntVector",
"clauseVec",
"=",
"new",
"LNGIntVector",
"(",
"literals",
".",
"size",
"(",
")",
")",
";",
"for",
"(",
"final",
... | Generates a clause vector of a collection of literals.
@param literals the literals
@return the clause vector | [
"Generates",
"a",
"clause",
"vector",
"of",
"a",
"collection",
"of",
"literals",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/MiniSat.java#L468-L480 | train |
logic-ng/LogicNG | src/main/java/org/logicng/bdds/datastructures/BDD.java | BDD.restrict | 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);
} | java | 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);
} | [
"public",
"BDD",
"restrict",
"(",
"final",
"Collection",
"<",
"Literal",
">",
"restriction",
")",
"{",
"final",
"BDD",
"resBDD",
"=",
"this",
".",
"factory",
".",
"build",
"(",
"this",
".",
"factory",
".",
"getF",
"(",
")",
".",
"and",
"(",
"restrictio... | Restricts the BDD.
@param restriction the restriction
@return the restricted BDD | [
"Restricts",
"the",
"BDD",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/bdds/datastructures/BDD.java#L169-L172 | train |
logic-ng/LogicNG | src/main/java/org/logicng/bdds/datastructures/BDD.java | BDD.exists | 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);
} | java | 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);
} | [
"public",
"BDD",
"exists",
"(",
"final",
"Collection",
"<",
"Variable",
">",
"variables",
")",
"{",
"final",
"BDD",
"resBDD",
"=",
"this",
".",
"factory",
".",
"build",
"(",
"this",
".",
"factory",
".",
"getF",
"(",
")",
".",
"and",
"(",
"variables",
... | Existential quantifier elimination for a given set of variables.
@param variables the variables to eliminate
@return the BDD with the eliminated variables | [
"Existential",
"quantifier",
"elimination",
"for",
"a",
"given",
"set",
"of",
"variables",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/bdds/datastructures/BDD.java#L188-L191 | train |
logic-ng/LogicNG | src/main/java/org/logicng/bdds/datastructures/BDD.java | BDD.forall | 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);
} | java | 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);
} | [
"public",
"BDD",
"forall",
"(",
"final",
"Collection",
"<",
"Variable",
">",
"variables",
")",
"{",
"final",
"BDD",
"resBDD",
"=",
"this",
".",
"factory",
".",
"build",
"(",
"this",
".",
"factory",
".",
"getF",
"(",
")",
".",
"and",
"(",
"variables",
... | Universal quantifier elimination for a given set of variables.
@param variables the variables to eliminate
@return the BDD with the eliminated variables | [
"Universal",
"quantifier",
"elimination",
"for",
"a",
"given",
"set",
"of",
"variables",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/bdds/datastructures/BDD.java#L207-L210 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/printer/FormulaStringRepresentation.java | FormulaStringRepresentation.bracket | protected String bracket(final Formula formula) {
return String.format("%s%s%s", this.lbr(), this.toString(formula), this.rbr());
} | java | protected String bracket(final Formula formula) {
return String.format("%s%s%s", this.lbr(), this.toString(formula), this.rbr());
} | [
"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.
@param formula the formula
@return {@code "(" + formula.toString() + ")"} | [
"Returns",
"a",
"bracketed",
"string",
"version",
"of",
"a",
"given",
"formula",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/printer/FormulaStringRepresentation.java#L87-L89 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/printer/FormulaStringRepresentation.java | FormulaStringRepresentation.binaryOperator | 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);
} | java | 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);
} | [
"protected",
"String",
"binaryOperator",
"(",
"final",
"BinaryOperator",
"operator",
",",
"final",
"String",
"opString",
")",
"{",
"final",
"String",
"leftString",
"=",
"operator",
".",
"type",
"(",
")",
".",
"precedence",
"(",
")",
"<",
"operator",
".",
"le... | Returns the string representation of a binary operator.
@param operator the binary operator
@param opString the operator string
@return the string representation | [
"Returns",
"the",
"string",
"representation",
"of",
"a",
"binary",
"operator",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/printer/FormulaStringRepresentation.java#L98-L104 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/printer/FormulaStringRepresentation.java | FormulaStringRepresentation.naryOperator | 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();
} | java | 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();
} | [
"protected",
"String",
"naryOperator",
"(",
"final",
"NAryOperator",
"operator",
",",
"final",
"String",
"opString",
")",
"{",
"final",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"int",
"count",
"=",
"0",
";",
"final",
"int",
"size",
... | Returns the string representation of an n-ary operator.
@param operator the n-ary operator
@param opString the operator string
@return the string representation | [
"Returns",
"the",
"string",
"representation",
"of",
"an",
"n",
"-",
"ary",
"operator",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/printer/FormulaStringRepresentation.java#L113-L130 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/printer/FormulaStringRepresentation.java | FormulaStringRepresentation.pbLhs | 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();
} | java | 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();
} | [
"protected",
"String",
"pbLhs",
"(",
"final",
"Literal",
"[",
"]",
"operands",
",",
"final",
"int",
"[",
"]",
"coefficients",
")",
"{",
"assert",
"operands",
".",
"length",
"==",
"coefficients",
".",
"length",
";",
"final",
"StringBuilder",
"sb",
"=",
"new... | Returns the string representation of the left-hand side of a pseudo-Boolean constraint.
@param operands the literals of the constraint
@param coefficients the coefficients of the constraint
@return the string representation | [
"Returns",
"the",
"string",
"representation",
"of",
"the",
"left",
"-",
"hand",
"side",
"of",
"a",
"pseudo",
"-",
"Boolean",
"constraint",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/printer/FormulaStringRepresentation.java#L139-L159 | train |
logic-ng/LogicNG | src/main/java/org/logicng/explanations/unsatcores/drup/DRUPTrim.java | DRUPTrim.compute | 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;
} | java | 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;
} | [
"public",
"DRUPResult",
"compute",
"(",
"final",
"LNGVector",
"<",
"LNGIntVector",
">",
"originalProblem",
",",
"final",
"LNGVector",
"<",
"LNGIntVector",
">",
"proof",
")",
"{",
"final",
"DRUPResult",
"result",
"=",
"new",
"DRUPResult",
"(",
")",
";",
"Solver... | Computes the DRUP result for a given problem in terms of original clauses and the generated proof.
@param originalProblem the clauses of the original problem
@param proof the clauses of the proof
@return the result of the DRUP execution from which the UNSAT core can be generated | [
"Computes",
"the",
"DRUP",
"result",
"for",
"a",
"given",
"problem",
"in",
"terms",
"of",
"original",
"clauses",
"and",
"the",
"generated",
"proof",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/explanations/unsatcores/drup/DRUPTrim.java#L95-L107 | train |
logic-ng/LogicNG | src/main/java/org/logicng/transformations/qmc/Term.java | Term.countNonNegativeBits | private int countNonNegativeBits(final Tristate[] bits) {
int result = 0;
for (final Tristate bit : bits)
if (bit != Tristate.FALSE)
result++;
return result;
} | java | private int countNonNegativeBits(final Tristate[] bits) {
int result = 0;
for (final Tristate bit : bits)
if (bit != Tristate.FALSE)
result++;
return result;
} | [
"private",
"int",
"countNonNegativeBits",
"(",
"final",
"Tristate",
"[",
"]",
"bits",
")",
"{",
"int",
"result",
"=",
"0",
";",
"for",
"(",
"final",
"Tristate",
"bit",
":",
"bits",
")",
"if",
"(",
"bit",
"!=",
"Tristate",
".",
"FALSE",
")",
"result",
... | Counts the number of non-negative bits of a given tristate vector.
@param bits the tristate vector
@return the number of non-negative bits | [
"Counts",
"the",
"number",
"of",
"non",
"-",
"negative",
"bits",
"of",
"a",
"given",
"tristate",
"vector",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/transformations/qmc/Term.java#L74-L80 | train |
logic-ng/LogicNG | src/main/java/org/logicng/transformations/qmc/Term.java | Term.computeUndefNum | 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;
} | java | 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;
} | [
"private",
"long",
"computeUndefNum",
"(",
"final",
"Tristate",
"[",
"]",
"bits",
")",
"{",
"long",
"sum",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"bits",
".",
"length",
"-",
"1",
";",
"i",
">=",
"0",
";",
"i",
"--",
")",
"if",
"(",
"bits",... | Computes a number representing the number and position of the UNDEF states in the bit array.
@param bits the bit array
@return the computed number | [
"Computes",
"a",
"number",
"representing",
"the",
"number",
"and",
"position",
"of",
"the",
"UNDEF",
"states",
"in",
"the",
"bit",
"array",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/transformations/qmc/Term.java#L87-L93 | train |
logic-ng/LogicNG | src/main/java/org/logicng/transformations/qmc/Term.java | Term.translateToFormula | 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);
} | java | 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);
} | [
"Formula",
"translateToFormula",
"(",
"final",
"List",
"<",
"Variable",
">",
"varOrder",
")",
"{",
"final",
"FormulaFactory",
"f",
"=",
"varOrder",
".",
"get",
"(",
"0",
")",
".",
"factory",
"(",
")",
";",
"assert",
"this",
".",
"bits",
".",
"length",
... | Translates this term to a formula for a given variable ordering
@param varOrder the variable ordering
@return the translation of this term to a formula | [
"Translates",
"this",
"term",
"to",
"a",
"formula",
"for",
"a",
"given",
"variable",
"ordering"
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/transformations/qmc/Term.java#L169-L177 | train |
logic-ng/LogicNG | src/main/java/org/logicng/graphs/io/GraphDotFileWriter.java | GraphDotFileWriter.write | public static <T> void write(final String fileName, final Graph<T> graph) throws IOException {
write(new File(fileName.endsWith(".dot") ? fileName : fileName + ".dot"), graph);
} | java | public static <T> void write(final String fileName, final Graph<T> graph) throws IOException {
write(new File(fileName.endsWith(".dot") ? fileName : fileName + ".dot"), graph);
} | [
"public",
"static",
"<",
"T",
">",
"void",
"write",
"(",
"final",
"String",
"fileName",
",",
"final",
"Graph",
"<",
"T",
">",
"graph",
")",
"throws",
"IOException",
"{",
"write",
"(",
"new",
"File",
"(",
"fileName",
".",
"endsWith",
"(",
"\".dot\"",
")... | Writes a given formula's internal data structure as a dimacs file.
@param fileName the file name of the dimacs file to write
@param graph the graph
@param <T> the type of the graph content
@throws IOException if there was a problem writing the file | [
"Writes",
"a",
"given",
"formula",
"s",
"internal",
"data",
"structure",
"as",
"a",
"dimacs",
"file",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/graphs/io/GraphDotFileWriter.java#L64-L66 | train |
logic-ng/LogicNG | src/main/java/org/logicng/graphs/io/GraphDotFileWriter.java | GraphDotFileWriter.write | 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();
}
} | java | 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();
}
} | [
"public",
"static",
"<",
"T",
">",
"void",
"write",
"(",
"final",
"File",
"file",
",",
"final",
"Graph",
"<",
"T",
">",
"graph",
")",
"throws",
"IOException",
"{",
"final",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
"String",
".",
"format",... | Writes a given graph's internal data structure as a dot file.
@param file the file of the dot file to write
@param graph the graph
@param <T> the type of the graph content
@throws IOException if there was a problem writing the file | [
"Writes",
"a",
"given",
"graph",
"s",
"internal",
"data",
"structure",
"as",
"a",
"dot",
"file",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/graphs/io/GraphDotFileWriter.java#L75-L96 | train |
logic-ng/LogicNG | src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java | CCEncoder.encode | public ImmutableFormulaList encode(final PBConstraint cc) {
final EncodingResult result = EncodingResult.resultForFormula(f);
this.encodeConstraint(cc, result);
return new ImmutableFormulaList(FType.AND, result.result());
} | java | public ImmutableFormulaList encode(final PBConstraint cc) {
final EncodingResult result = EncodingResult.resultForFormula(f);
this.encodeConstraint(cc, result);
return new ImmutableFormulaList(FType.AND, result.result());
} | [
"public",
"ImmutableFormulaList",
"encode",
"(",
"final",
"PBConstraint",
"cc",
")",
"{",
"final",
"EncodingResult",
"result",
"=",
"EncodingResult",
".",
"resultForFormula",
"(",
"f",
")",
";",
"this",
".",
"encodeConstraint",
"(",
"cc",
",",
"result",
")",
"... | Encodes a cardinality constraint and returns its CNF encoding.
@param cc the cardinality constraint
@return the CNF encoding of the cardinality constraint | [
"Encodes",
"a",
"cardinality",
"constraint",
"and",
"returns",
"its",
"CNF",
"encoding",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java#L120-L124 | train |
logic-ng/LogicNG | src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java | CCEncoder.encodeIncremental | 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);
} | java | 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);
} | [
"public",
"Pair",
"<",
"ImmutableFormulaList",
",",
"CCIncrementalData",
">",
"encodeIncremental",
"(",
"final",
"PBConstraint",
"cc",
")",
"{",
"final",
"EncodingResult",
"result",
"=",
"EncodingResult",
".",
"resultForFormula",
"(",
"f",
")",
";",
"final",
"CCIn... | Encodes an incremental cardinality constraint and returns its encoding.
@param cc the cardinality constraint
@return the encoding of the constraint and the incremental data | [
"Encodes",
"an",
"incremental",
"cardinality",
"constraint",
"and",
"returns",
"its",
"encoding",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java#L140-L144 | train |
logic-ng/LogicNG | src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java | CCEncoder.encodeConstraint | 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());
}
} | java | 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());
}
} | [
"private",
"void",
"encodeConstraint",
"(",
"final",
"PBConstraint",
"cc",
",",
"final",
"EncodingResult",
"result",
")",
"{",
"if",
"(",
"!",
"cc",
".",
"isCC",
"(",
")",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Cannot encode a non-cardinality con... | Encodes the constraint in the given result.
@param cc the constraint
@param result the result | [
"Encodes",
"the",
"constraint",
"in",
"the",
"given",
"result",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java#L198-L230 | train |
logic-ng/LogicNG | src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java | CCEncoder.amk | 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) // there is no constraint
return;
if (rhs == 0) { // no variable can be true
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);
}
} | java | 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) // there is no constraint
return;
if (rhs == 0) { // no variable can be true
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);
}
} | [
"private",
"void",
"amk",
"(",
"final",
"EncodingResult",
"result",
",",
"final",
"Variable",
"[",
"]",
"vars",
",",
"int",
"rhs",
")",
"{",
"if",
"(",
"rhs",
"<",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid right hand side of cardina... | Encodes an at-most-k constraint.
@param result the result
@param vars the variables of the constraint
@param rhs the right hand side of the constraint | [
"Encodes",
"an",
"at",
"-",
"most",
"-",
"k",
"constraint",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java#L323-L355 | train |
logic-ng/LogicNG | src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java | CCEncoder.alk | 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);
}
} | java | 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);
}
} | [
"private",
"void",
"alk",
"(",
"final",
"EncodingResult",
"result",
",",
"final",
"Variable",
"[",
"]",
"vars",
",",
"int",
"rhs",
")",
"{",
"if",
"(",
"rhs",
"<",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid right hand side of cardina... | Encodes an at-lest-k constraint.
@param result the result
@param vars the variables of the constraint
@param rhs the right hand side of the constraint | [
"Encodes",
"an",
"at",
"-",
"lest",
"-",
"k",
"constraint",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java#L404-L444 | train |
logic-ng/LogicNG | src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java | CCEncoder.exk | 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);
}
} | java | 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);
}
} | [
"private",
"void",
"exk",
"(",
"final",
"EncodingResult",
"result",
",",
"final",
"Variable",
"[",
"]",
"vars",
",",
"int",
"rhs",
")",
"{",
"if",
"(",
"rhs",
"<",
"0",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Invalid right hand side of cardina... | Encodes an exactly-k constraint.
@param result the result
@param vars the variables of the constraint
@param rhs the right hand side of the constraint | [
"Encodes",
"an",
"exactly",
"-",
"k",
"constraint",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java#L501-L535 | train |
logic-ng/LogicNG | src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java | CCEncoder.bestAMO | 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;
}
} | java | 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;
}
} | [
"private",
"CCAtMostOne",
"bestAMO",
"(",
"int",
"n",
")",
"{",
"if",
"(",
"n",
"<=",
"10",
")",
"{",
"if",
"(",
"this",
".",
"amoPure",
"==",
"null",
")",
"this",
".",
"amoPure",
"=",
"new",
"CCAMOPure",
"(",
")",
";",
"return",
"this",
".",
"am... | 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.
@param n the number of variables
@return the best at-most-one encoder | [
"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",
"pur... | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/cardinalityconstraints/CCEncoder.java#L544-L554 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/SATSolver.java | SATSolver.addWithRelaxation | public void addWithRelaxation(final Variable relaxationVar, final ImmutableFormulaList formulas) {
for (final Formula formula : formulas) { this.addWithRelaxation(relaxationVar, formula); }
} | java | public void addWithRelaxation(final Variable relaxationVar, final ImmutableFormulaList formulas) {
for (final Formula formula : formulas) { this.addWithRelaxation(relaxationVar, formula); }
} | [
"public",
"void",
"addWithRelaxation",
"(",
"final",
"Variable",
"relaxationVar",
",",
"final",
"ImmutableFormulaList",
"formulas",
")",
"{",
"for",
"(",
"final",
"Formula",
"formula",
":",
"formulas",
")",
"{",
"this",
".",
"addWithRelaxation",
"(",
"relaxationVa... | Adds a formula list to the solver.
@param relaxationVar the relaxation variable
@param formulas the formula list | [
"Adds",
"a",
"formula",
"list",
"to",
"the",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/SATSolver.java#L152-L154 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/SATSolver.java | SATSolver.addWithRelaxation | public void addWithRelaxation(final Variable relaxationVar, final Collection<? extends Formula> formulas) {
for (final Formula formula : formulas) { this.addWithRelaxation(relaxationVar, formula); }
} | java | public void addWithRelaxation(final Variable relaxationVar, final Collection<? extends Formula> formulas) {
for (final Formula formula : formulas) { this.addWithRelaxation(relaxationVar, formula); }
} | [
"public",
"void",
"addWithRelaxation",
"(",
"final",
"Variable",
"relaxationVar",
",",
"final",
"Collection",
"<",
"?",
"extends",
"Formula",
">",
"formulas",
")",
"{",
"for",
"(",
"final",
"Formula",
"formula",
":",
"formulas",
")",
"{",
"this",
".",
"addWi... | Adds a collection of formulas to the solver.
@param relaxationVar the relaxation variable
@param formulas the collection of formulas | [
"Adds",
"a",
"collection",
"of",
"formulas",
"to",
"the",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/SATSolver.java#L161-L163 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/SATSolver.java | SATSolver.addClauseSetWithRelaxation | 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);
}
} | java | 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);
}
} | [
"private",
"void",
"addClauseSetWithRelaxation",
"(",
"final",
"Variable",
"relaxationVar",
",",
"final",
"Formula",
"formula",
")",
"{",
"switch",
"(",
"formula",
".",
"type",
"(",
")",
")",
"{",
"case",
"TRUE",
":",
"break",
";",
"case",
"FALSE",
":",
"c... | Adds a formula which is already in CNF with a given relaxation to the solver.
@param relaxationVar the relaxation variable
@param formula the formula in CNF | [
"Adds",
"a",
"formula",
"which",
"is",
"already",
"in",
"CNF",
"with",
"a",
"given",
"relaxation",
"to",
"the",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/SATSolver.java#L205-L220 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/SATSolver.java | SATSolver.enumerateAllModels | public List<Assignment> enumerateAllModels(final ModelEnumerationHandler handler) {
return this.enumerateAllModels((Collection<Variable>) null, handler);
} | java | public List<Assignment> enumerateAllModels(final ModelEnumerationHandler handler) {
return this.enumerateAllModels((Collection<Variable>) null, handler);
} | [
"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.
@param handler the model enumeration handler
@return the list of models | [
"Enumerates",
"all",
"models",
"of",
"the",
"current",
"formula",
"and",
"passes",
"it",
"to",
"a",
"model",
"enumeration",
"handler",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/SATSolver.java#L370-L372 | train |
logic-ng/LogicNG | src/main/java/org/logicng/graphs/datastructures/Node.java | Node.connectTo | 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);
} | java | 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);
} | [
"void",
"connectTo",
"(",
"final",
"Node",
"<",
"T",
">",
"o",
")",
"{",
"if",
"(",
"!",
"this",
".",
"graph",
".",
"equals",
"(",
"o",
".",
"graph",
")",
")",
"throw",
"new",
"IllegalArgumentException",
"(",
"\"Cannot connect to nodes of two different graph... | Adds the given node to the neighbours of this node. Both nodes must be in the same graph.
@param o the given node | [
"Adds",
"the",
"given",
"node",
"to",
"the",
"neighbours",
"of",
"this",
"node",
".",
"Both",
"nodes",
"must",
"be",
"in",
"the",
"same",
"graph",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/graphs/datastructures/Node.java#L61-L68 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.luby | 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);
} | java | 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);
} | [
"protected",
"static",
"double",
"luby",
"(",
"double",
"y",
",",
"int",
"x",
")",
"{",
"int",
"intX",
"=",
"x",
";",
"int",
"size",
"=",
"1",
";",
"int",
"seq",
"=",
"0",
";",
"while",
"(",
"size",
"<",
"intX",
"+",
"1",
")",
"{",
"seq",
"++... | Computes the next number in the Luby sequence.
@param y the restart increment
@param x the current number of restarts
@return the next number in the Luby sequence | [
"Computes",
"the",
"next",
"number",
"in",
"the",
"Luby",
"sequence",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L175-L189 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.initializeConfig | 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;
} | java | 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;
} | [
"private",
"void",
"initializeConfig",
"(",
")",
"{",
"this",
".",
"varDecay",
"=",
"this",
".",
"config",
".",
"varDecay",
";",
"this",
".",
"varInc",
"=",
"this",
".",
"config",
".",
"varInc",
";",
"this",
".",
"ccminMode",
"=",
"this",
".",
"config"... | Initializes the solver configuration. | [
"Initializes",
"the",
"solver",
"configuration",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L229-L240 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.value | protected Tristate value(int lit) {
return sign(lit) ? Tristate.negate(this.v(lit).assignment()) : this.v(lit).assignment();
} | java | protected Tristate value(int lit) {
return sign(lit) ? Tristate.negate(this.v(lit).assignment()) : this.v(lit).assignment();
} | [
"protected",
"Tristate",
"value",
"(",
"int",
"lit",
")",
"{",
"return",
"sign",
"(",
"lit",
")",
"?",
"Tristate",
".",
"negate",
"(",
"this",
".",
"v",
"(",
"lit",
")",
".",
"assignment",
"(",
")",
")",
":",
"this",
".",
"v",
"(",
"lit",
")",
... | Returns the assigned value of a given literal.
@param lit the literal
@return the assigned value of the literal | [
"Returns",
"the",
"assigned",
"value",
"of",
"a",
"given",
"literal",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L256-L258 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.lt | public boolean lt(int x, int y) {
return this.vars.get(x).activity() > this.vars.get(y).activity();
} | java | public boolean lt(int x, int y) {
return this.vars.get(x).activity() > this.vars.get(y).activity();
} | [
"public",
"boolean",
"lt",
"(",
"int",
"x",
",",
"int",
"y",
")",
"{",
"return",
"this",
".",
"vars",
".",
"get",
"(",
"x",
")",
".",
"activity",
"(",
")",
">",
"this",
".",
"vars",
".",
"get",
"(",
"y",
")",
".",
"activity",
"(",
")",
";",
... | Compares two variables by their activity.
@param x the first variable
@param y the second variable
@return {@code true} if the first variable's activity is larger then the second one's | [
"Compares",
"two",
"variables",
"by",
"their",
"activity",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L266-L268 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.idxForName | public int idxForName(final String name) {
final Integer id = this.name2idx.get(name);
return id == null ? -1 : id;
} | java | public int idxForName(final String name) {
final Integer id = this.name2idx.get(name);
return id == null ? -1 : id;
} | [
"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.
@param name the variable name
@return the variable index for the name | [
"Returns",
"the",
"variable",
"index",
"for",
"a",
"given",
"variable",
"name",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L275-L278 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.addName | public void addName(final String name, int id) {
this.name2idx.put(name, id);
this.idx2name.put(id, name);
} | java | public void addName(final String name, int id) {
this.name2idx.put(name, id);
this.idx2name.put(id, name);
} | [
"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.
@param name the variable name
@param id the variable index | [
"Adds",
"a",
"new",
"variable",
"name",
"with",
"a",
"given",
"variable",
"index",
"to",
"this",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L294-L297 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.addClause | public boolean addClause(int lit, final Proposition proposition) {
final LNGIntVector unit = new LNGIntVector(1);
unit.push(lit);
return this.addClause(unit, proposition);
} | java | public boolean addClause(int lit, final Proposition proposition) {
final LNGIntVector unit = new LNGIntVector(1);
unit.push(lit);
return this.addClause(unit, proposition);
} | [
"public",
"boolean",
"addClause",
"(",
"int",
"lit",
",",
"final",
"Proposition",
"proposition",
")",
"{",
"final",
"LNGIntVector",
"unit",
"=",
"new",
"LNGIntVector",
"(",
"1",
")",
";",
"unit",
".",
"push",
"(",
"lit",
")",
";",
"return",
"this",
".",
... | Adds a unit clause to the solver.
@param lit the unit clause's literal
@param proposition a proposition (if required for proof tracing)
@return {@code true} if the clause was added successfully, {@code false} otherwise | [
"Adds",
"a",
"unit",
"clause",
"to",
"the",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L314-L318 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.pickBranchLit | 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());
} | java | 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());
} | [
"protected",
"int",
"pickBranchLit",
"(",
")",
"{",
"int",
"next",
"=",
"-",
"1",
";",
"while",
"(",
"next",
"==",
"-",
"1",
"||",
"this",
".",
"vars",
".",
"get",
"(",
"next",
")",
".",
"assignment",
"(",
")",
"!=",
"Tristate",
".",
"UNDEF",
"||... | Picks the next branching literal.
@return the literal or -1 if there are no unassigned literals left | [
"Picks",
"the",
"next",
"branching",
"literal",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L452-L460 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.varBumpActivity | 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);
} | java | 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);
} | [
"protected",
"void",
"varBumpActivity",
"(",
"int",
"v",
",",
"double",
"inc",
")",
"{",
"final",
"MSVariable",
"var",
"=",
"this",
".",
"vars",
".",
"get",
"(",
"v",
")",
";",
"var",
".",
"incrementActivity",
"(",
"inc",
")",
";",
"if",
"(",
"var",
... | Bumps the activity of the variable at a given index by a given value.
@param v the variable index
@param inc the increment value | [
"Bumps",
"the",
"activity",
"of",
"the",
"variable",
"at",
"a",
"given",
"index",
"by",
"a",
"given",
"value",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L482-L492 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.rebuildOrderHeap | 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);
} | java | 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);
} | [
"protected",
"void",
"rebuildOrderHeap",
"(",
")",
"{",
"final",
"LNGIntVector",
"vs",
"=",
"new",
"LNGIntVector",
"(",
")",
";",
"for",
"(",
"int",
"v",
"=",
"0",
";",
"v",
"<",
"this",
".",
"nVars",
"(",
")",
";",
"v",
"++",
")",
"if",
"(",
"th... | Rebuilds the heap of decision variables. | [
"Rebuilds",
"the",
"heap",
"of",
"decision",
"variables",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L497-L503 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java | MiniSatStyleSolver.claBumpActivity | protected void claBumpActivity(final MSClause c) {
c.incrementActivity(claInc);
if (c.activity() > 1e20) {
for (final MSClause clause : learnts)
clause.rescaleActivity();
claInc *= 1e-20;
}
} | java | protected void claBumpActivity(final MSClause c) {
c.incrementActivity(claInc);
if (c.activity() > 1e20) {
for (final MSClause clause : learnts)
clause.rescaleActivity();
claInc *= 1e-20;
}
} | [
"protected",
"void",
"claBumpActivity",
"(",
"final",
"MSClause",
"c",
")",
"{",
"c",
".",
"incrementActivity",
"(",
"claInc",
")",
";",
"if",
"(",
"c",
".",
"activity",
"(",
")",
">",
"1e20",
")",
"{",
"for",
"(",
"final",
"MSClause",
"clause",
":",
... | Bumps the activity of the given clause.
@param c the clause | [
"Bumps",
"the",
"activity",
"of",
"the",
"given",
"clause",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/sat/MiniSatStyleSolver.java#L525-L532 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/maxsat/encodings/Ladder.java | Ladder.encode | 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)));
}
}
}
} | java | 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)));
}
}
}
} | [
"public",
"void",
"encode",
"(",
"final",
"MiniSatStyleSolver",
"s",
",",
"final",
"LNGIntVector",
"lits",
")",
"{",
"assert",
"lits",
".",
"size",
"(",
")",
"!=",
"0",
";",
"if",
"(",
"lits",
".",
"size",
"(",
")",
"==",
"1",
")",
"addUnitClause",
"... | Encodes and adds the AMO constraint to the given solver.
@param s the solver
@param lits the literals for the constraint | [
"Encodes",
"and",
"adds",
"the",
"AMO",
"constraint",
"to",
"the",
"given",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/maxsat/encodings/Ladder.java#L72-L97 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/Formula.java | Formula.substitute | public Formula substitute(final Variable variable, final Formula formula) {
final Substitution subst = new Substitution();
subst.addMapping(variable, formula);
return this.substitute(subst);
} | java | public Formula substitute(final Variable variable, final Formula formula) {
final Substitution subst = new Substitution();
subst.addMapping(variable, formula);
return this.substitute(subst);
} | [
"public",
"Formula",
"substitute",
"(",
"final",
"Variable",
"variable",
",",
"final",
"Formula",
"formula",
")",
"{",
"final",
"Substitution",
"subst",
"=",
"new",
"Substitution",
"(",
")",
";",
"subst",
".",
"addMapping",
"(",
"variable",
",",
"formula",
"... | Performs a simultaneous substitution on this formula given a single mapping from variable to formula.
@param variable the variable
@param formula the formula
@return a new substituted formula | [
"Performs",
"a",
"simultaneous",
"substitution",
"on",
"this",
"formula",
"given",
"a",
"single",
"mapping",
"from",
"variable",
"to",
"formula",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/Formula.java#L191-L195 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/Formula.java | Formula.apply | public <T> T apply(final FormulaFunction<T> function, final boolean cache) {
return function.apply(this, cache);
} | java | public <T> T apply(final FormulaFunction<T> function, final boolean cache) {
return function.apply(this, cache);
} | [
"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.
@param function the function
@param cache indicates whether the result should be cached in this formula's cache
@param <T> the result type of the function
@return the result of the function application | [
"Applies",
"a",
"given",
"function",
"on",
"this",
"formula",
"and",
"returns",
"the",
"result",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/Formula.java#L317-L319 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/Formula.java | Formula.predicateCacheEntry | public Tristate predicateCacheEntry(final CacheEntry key) {
final Tristate tristate = this.predicateCache.get(key);
if (tristate == null) {
return Tristate.UNDEF;
}
return tristate;
} | java | public Tristate predicateCacheEntry(final CacheEntry key) {
final Tristate tristate = this.predicateCache.get(key);
if (tristate == null) {
return Tristate.UNDEF;
}
return tristate;
} | [
"public",
"Tristate",
"predicateCacheEntry",
"(",
"final",
"CacheEntry",
"key",
")",
"{",
"final",
"Tristate",
"tristate",
"=",
"this",
".",
"predicateCache",
".",
"get",
"(",
"key",
")",
";",
"if",
"(",
"tristate",
"==",
"null",
")",
"{",
"return",
"Trist... | Returns an entry of the predicate cache of this formula.
@param key the cache key
@return the cache value (which is {@code UNDEF} if nothing is present) | [
"Returns",
"an",
"entry",
"of",
"the",
"predicate",
"cache",
"of",
"this",
"formula",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/Formula.java#L354-L360 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/Formula.java | Formula.setPredicateCacheEntry | public void setPredicateCacheEntry(final CacheEntry key, final boolean value) {
this.predicateCache.put(key, Tristate.fromBool(value));
} | java | public void setPredicateCacheEntry(final CacheEntry key, final boolean value) {
this.predicateCache.put(key, Tristate.fromBool(value));
} | [
"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
@param key the cache key
@param value the cache value | [
"Sets",
"an",
"entry",
"in",
"the",
"predicate",
"cache",
"of",
"this",
"formula"
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/Formula.java#L367-L369 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/PBConstraint.java | PBConstraint.evaluateCoeffs | 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");
}
} | java | 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");
}
} | [
"static",
"Tristate",
"evaluateCoeffs",
"(",
"final",
"int",
"minValue",
",",
"final",
"int",
"maxValue",
",",
"final",
"int",
"rhs",
",",
"final",
"CType",
"comparator",
")",
"{",
"int",
"status",
"=",
"0",
";",
"if",
"(",
"rhs",
">=",
"minValue",
")",
... | 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.
@param minValue the minimum coefficient sum
@param maxValue the maximum coefficient sum
@param rhs the right-hand-side
@param comparator the comparator
@return {@link Tristate#TRUE} if the constraint is true, {@link Tristate#FALSE} if it is false and
{@link Tristate#UNDEF} if both are still possible | [
"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",
"com... | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/PBConstraint.java#L170-L195 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/PBConstraint.java | PBConstraint.normalize | 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);
}
} | java | 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);
}
} | [
"public",
"Formula",
"normalize",
"(",
")",
"{",
"final",
"LNGVector",
"<",
"Literal",
">",
"normPs",
"=",
"new",
"LNGVector",
"<>",
"(",
"this",
".",
"literals",
".",
"length",
")",
";",
"final",
"LNGIntVector",
"normCs",
"=",
"new",
"LNGIntVector",
"(",
... | Normalizes this constraint s.t. it can be converted to CNF.
@return the normalized constraint | [
"Normalizes",
"this",
"constraint",
"s",
".",
"t",
".",
"it",
"can",
"be",
"converted",
"to",
"CNF",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/PBConstraint.java#L265-L305 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/PBConstraint.java | PBConstraint.evaluateLHS | 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;
} | java | 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;
} | [
"private",
"int",
"evaluateLHS",
"(",
"final",
"Assignment",
"assignment",
")",
"{",
"int",
"lhs",
"=",
"0",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"this",
".",
"literals",
".",
"length",
";",
"i",
"++",
")",
"if",
"(",
"this",
"."... | Returns the evaluation of the left-hand side of this constraint.
@param assignment the assignment
@return the evaluation of the left-hand side of this constraint | [
"Returns",
"the",
"evaluation",
"of",
"the",
"left",
"-",
"hand",
"side",
"of",
"this",
"constraint",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/PBConstraint.java#L571-L577 | train |
logic-ng/LogicNG | src/main/java/org/logicng/formulas/PBConstraint.java | PBConstraint.evaluateComparator | 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");
}
} | java | 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");
}
} | [
"private",
"boolean",
"evaluateComparator",
"(",
"final",
"int",
"lhs",
")",
"{",
"switch",
"(",
"this",
".",
"comparator",
")",
"{",
"case",
"EQ",
":",
"return",
"lhs",
"==",
"this",
".",
"rhs",
";",
"case",
"LE",
":",
"return",
"lhs",
"<=",
"this",
... | Computes the result of evaluating the comparator with a given left-hand side.
@param lhs the left-hand side
@return {@code true} if the comparator evaluates to true, {@code false} otherwise | [
"Computes",
"the",
"result",
"of",
"evaluating",
"the",
"comparator",
"with",
"a",
"given",
"left",
"-",
"hand",
"side",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/formulas/PBConstraint.java#L584-L599 | train |
logic-ng/LogicNG | src/main/java/org/logicng/graphs/io/GraphDimacsFileWriter.java | GraphDimacsFileWriter.write | 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);
}
} | java | 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);
}
} | [
"public",
"static",
"<",
"T",
">",
"void",
"write",
"(",
"final",
"String",
"fileName",
",",
"Graph",
"<",
"T",
">",
"g",
",",
"boolean",
"writeMapping",
")",
"throws",
"IOException",
"{",
"File",
"file",
"=",
"new",
"File",
"(",
"fileName",
".",
"ends... | Writes a given graph's internal data structure as a dimacs file.
@param fileName the file name of the dimacs file to write
@param g the graph
@param writeMapping indicates whether an additional file for translating the ids to variable names shall be written
@param <T> the type of the graph content
@throws IOException if there was a problem writing the file | [
"Writes",
"a",
"given",
"graph",
"s",
"internal",
"data",
"structure",
"as",
"a",
"dimacs",
"file",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/graphs/io/GraphDimacsFileWriter.java#L68-L101 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/CleaneLing.java | CleaneLing.minimalistic | public static CleaneLing minimalistic(final FormulaFactory f) {
return new CleaneLing(f, SolverStyle.MINIMALISTIC, new CleaneLingConfig.Builder().build());
} | java | public static CleaneLing minimalistic(final FormulaFactory f) {
return new CleaneLing(f, SolverStyle.MINIMALISTIC, new CleaneLingConfig.Builder().build());
} | [
"public",
"static",
"CleaneLing",
"minimalistic",
"(",
"final",
"FormulaFactory",
"f",
")",
"{",
"return",
"new",
"CleaneLing",
"(",
"f",
",",
"SolverStyle",
".",
"MINIMALISTIC",
",",
"new",
"CleaneLingConfig",
".",
"Builder",
"(",
")",
".",
"build",
"(",
")... | Returns a new minimalistic CleaneLing solver.
@param f the formula factory
@return the solver | [
"Returns",
"a",
"new",
"minimalistic",
"CleaneLing",
"solver",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/CleaneLing.java#L118-L120 | train |
logic-ng/LogicNG | src/main/java/org/logicng/solvers/CleaneLing.java | CleaneLing.minimalistic | public static CleaneLing minimalistic(final FormulaFactory f, final CleaneLingConfig config) {
return new CleaneLing(f, SolverStyle.MINIMALISTIC, config);
} | java | public static CleaneLing minimalistic(final FormulaFactory f, final CleaneLingConfig config) {
return new CleaneLing(f, SolverStyle.MINIMALISTIC, config);
} | [
"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.
@param f the formula factory
@param config the configuration
@return the solver | [
"Returns",
"a",
"new",
"minimalistic",
"CleaneLing",
"solver",
"with",
"a",
"given",
"configuration",
"."
] | bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e | https://github.com/logic-ng/LogicNG/blob/bb9eb88a768be4be8e02a76cfc4a59e6c3fb7f2e/src/main/java/org/logicng/solvers/CleaneLing.java#L128-L130 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.