[JAVA] How to use JDD library in Scala with 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

How to use JDD library in Scala with Eclipse
How to use Eclipse Debug_Shell
How to switch Tomcat context.xml with WTP in Eclipse
How to use Lombok in Spring
How to use mssql-tools with alpine
How to use InjectorHolder in OpenAM
How to use classes in Java?
How to set Lombok in Eclipse
A memorandum on how to use Eclipse
Multilingual Locale in Java How to use Locale
How to use Apache Derby on Eclipse
How to use custom helpers in rails
How to use named volume in docker-compose.yml
How to use BootStrap with Play Framework
[Rails] How to use rails console with docker
How to include Spring Tool in Eclipse 4.6.3?
I want to use DBViewer with Eclipse 2018-12! !!
How to use Docker in VSCode DevContainer
How to use MySQL in Rails tutorial
How to use environment variables in RubyOnRails
How to publish a library in jCenter
Understand in 5 minutes !! How to use Docker
How to use credentials.yml.enc introduced in Rails 5.2
[For beginners] How to debug in Eclipse
How to use ExpandableListView in Android Studio
[JavaFX] How to write Eclipse permissions in build.gradle
How to color code console output in Eclipse
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
[Rails] How to use select boxes in Ransack
How to use built-in h2db with spring boot
How to use "sign_in" in integration test (RSpec)
How to use Java framework with AWS Lambda! ??
How to use Java API with lambda expression
How to use JQuery in js.erb of Rails6
How to use nfs protocol version 2 with ubuntu 18.04
How to use docker compose with NVIDIA Jetson
How to use nginx-ingress-controller with Docker for Mac
[Rails] How to use PostgreSQL in Vagrant environment
How to automatically generate a constructor in Eclipse
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
To debug in eclipse
How to use Twitter4J
How to use active_hash! !!
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
[How to use label]
How to use identity
How to use hashes
How to use JUnit 5
Use PostgreSQL in Scala
How to use Dozer.mapper
How to use Gradle
How to use org.immutables