[JAVA] Verwendung der JDD-Bibliothek in Scala mit Eclipse

Introduction In this post, I will show you how to use the jdd Java library with Scala in Eclipse Neon 3 IDE a Java BDD library.

Requirements

How to use it in Scala In this part, I will show you how to use the JDD library in Scala to get all solutions of SAT formula or just one. You have first to import the library :

import jdd.bdd.BDD

Initialization You need to initialize a BDD object by specify the size of initial node table and cache. We will use the values 1000 for the both parameters :

val bdd: BDD = new BDD(1000,1000)

Create variables After the BDD object is created, you can define some BDD variables like this :

val v1: Int = bdd.createVar()
val v2: Int = bdd.createVar()

Specify formula Finally, you can specify the formula you want to solve, just by calling the BDD operations :

val and: Int = bdd.and(v1,v2);
val or: Int = bdd.or(v1,v2)
val not: Int = bdd.not(v1)

Get one solution of SAT formula Now, if you want to get one solution from a formula, call the method oneSat from a BDD object with the reference of the formula and an array of size of the number of result of your formula, here it will be 2 :

val oneSolution: Array[Int] = bdd.oneSat(and, new Array(2))
oneSolution.map(f=>print(f))

// Result
11

Get all solutions of SAT formula If you want to get all solution from a formula, call the method printSet from a BDD object :

bdd.printSet(or)

// Result
01
1-

You can notice the result is "simplified", in fact the result you was maybe expecting would be something like that (see below) but the BDD library simplified the result with a "-" when it's possible :

01
10
11

By the way, the method printSet doesn't return anything so if you want to get the result, you have to redirect the output stream, like this :

val baos = new ByteArrayOutputStream(); // Create a stream to hold the output
val ps = new PrintStream(baos); 
val old = System.out;            // Store the current output stream
System.setOut(ps);               // Redefine the output stream 
bdd.printSet(or)                 // Call the method with the print statement
System.out.flush();              // Flush the print statement into the PrintStream ps
System.setOut(old);              // Restore the previous state of the output stream

for (line <- baos.toString().split("\n")) // Get the result line by line
{
   println(line)
}

// Result
01
1-

Sources Eclipse Neon, Scala IDE JDD Bitbucket Method to redirect the output stream

Also if you want to use different BDD library for different language like C, Python or an other language ; I recommend you to visit this web page which list some BDD libraries.

Recommended Posts

Verwendung der JDD-Bibliothek in Scala mit Eclipse
Verwendung von Eclipse Debug_Shell
So wechseln Sie Tomcat context.xml mit Eclipse WTP
Wie man Lombok im Frühling benutzt
Wie man mssql-tools mit alpine benutzt
Verwendung von InjectorHolder in OpenAM
Wie verwende ich Klassen in Java?
So setzen Sie Lombok in Eclipse
Ein Memorandum zur Verwendung von Eclipse
Mehrsprachige Unterstützung für Java Verwendung des Gebietsschemas
Verwendung von Apache Derby unter Eclipse
Verwendung des benannten Volumes in docker-compose.yml
Verwendung von BootStrap mit Play Framework
Wie kann ich Spring Tool in Eclipse 4.6.3 einbinden?
Ich möchte DBViewer mit Eclipse 2018-12 verwenden! !!
Verwendung von Docker in VSCode DevContainer
Verwendung von MySQL im Rails-Tutorial
Verwendung von Umgebungsvariablen in RubyOnRails
So veröffentlichen Sie eine Bibliothek in jCenter
Verstehe in 5 Minuten !! Wie man Docker benutzt
Verwendung von credentials.yml.enc aus Rails 5.2
[Für Anfänger] So debuggen Sie mit Eclipse
Verwendung von ExpandableListView in Android Studio
[Java FX] So schreiben Sie Eclipse-Berechtigungen in build.gradle
Farbcodierung der Konsolenausgabe in Eclipse
Verwendung von MyBatis2 (iBatis) mit Spring Boot 1.4 (Spring 4)
[Rails] Verwendung von Auswahlfeldern in Ransack
Verwendung des eingebauten h2db mit Federstiefel
Verwendung des Java-Frameworks mit AWS Lambda! ??
Verwendung der Java-API mit Lambda-Ausdrücken
Verwendung von JQuery in Rails 6 js.erb
Verwendung des NFS-Protokolls Version 2 mit Ubuntu 18.04
[Rails] Verwendung von PostgreSQL in einer Vagrant-Umgebung
So generieren Sie automatisch einen Konstruktor in Eclipse
Verwendung von Map
Wie benutzt man rbenv?
Verwendung mit_option
Verwendung von fields_for
Verwendung von java.util.logging
Verwendung der Karte
Verwendung von collection_select
Debuggen mit Eclipse
Wie benutzt man Twitter4J
Wie benutzt man active_hash! !!
Verwendung von MapStruct
Verwendung von TreeSet
[Verwendung des Etiketts]
Wie man Identität benutzt
Wie man Hash benutzt
Verwenden Sie PostgreSQL in Scala
Verwendung von Dozer.mapper
Wie benutzt man Gradle?
Verwendung von org.immutables