Skip to content

Commit

Permalink
rename the new format to implicant table and add documentation page
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelien-naldi committed Nov 29, 2018
1 parent cb1b605 commit 9e20f45
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 58 deletions.
2 changes: 1 addition & 1 deletion build-doc.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash

# config: set source doc and output
DOC="doc"
Expand Down
2 changes: 1 addition & 1 deletion doc/format-cnet.page
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<p>Format used by <link href="https://people.kth.se/~dubrova/bns.html">BNS</link>, a tool for the
identification of synchronous attractors.
Models are represented as a list of partial truth tables, similar to the Berkeley Logic Interchange Format.
Models are represented as a list of implicants (truth table entries with jokers) for each component, similar to the Berkeley Logic Interchange Format.
</p>

<code><![CDATA[
Expand Down
44 changes: 44 additions & 0 deletions doc/format-implicant-tables.page
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<page xmlns="http://projectmallard.org/1.0/"
type="topic"
id="format-implicant-tables">
<info>
<link type="guide" xref="index#formats"/>
<link type="guide" xref="formats#list"/>
<revision status="draft" date="2018-11-28"/>
<desc>Import/Export logical models as lists of implicant tables</desc>
</info>

<title>Implicant tables format</title>

<p>The implicant tables format supports importing and exporting models a list of implicants
(truth table entries with jokers). Each component of the model is described as a separate
table depending on its own regulators. It is similar to the CNET format but supports
multi-valued models and components identifiers are part of the format.
</p>

<p>
Each implicant table starts with a line listing the regulators and ending with the ID of the target component.
Similarly, each line of the table gives the value of each regulator (or '-' to match any value) and
ends with the target value. Lines with a target value of '0' can be skipped.
The '#' characters denote line-comments: everything following it on the same line is ignored.
Spacing characters are ignored and each value uses a single character (i.e. values higher than 9 are not supported).
</p>

<p>Sample file defining a Boolean model with three components:</p>

<code>
# Sample model defined as a list of implicant tables
# [A, B, D]

A : A
1:1

A : B
0:1

A B : D
11:1
</code>

</page>

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
grammar LTT;
grammar ITNET;

model: NEWLINE* table+;
table: var* SEP curvar ('[' max ']')? NEWLINE+ line*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
package org.colomoto.biolqm.io.truthtable;
package org.colomoto.biolqm.io.implicanttables;

import org.colomoto.biolqm.LogicalModel;
import org.colomoto.biolqm.NodeInfo;
import org.colomoto.biolqm.helper.implicants.RestrictedPathSearcher;
import org.colomoto.biolqm.io.BaseExporter;
import org.colomoto.mddlib.MDDManager;
import org.colomoto.mddlib.MDDVariable;
import org.colomoto.mddlib.PathSearcher;

import java.io.IOException;
import java.io.Writer;
import java.util.List;


/**
* Export logical model into cnet truth tables.
* Export logical model into lists of implicant tables.
*
* @author Hannes Klarner (minor modifications to a file of Aurelien Naldi)
* @author Hannes Klarner
* @author Aurelien Naldi
*/
public class LogicalTruthTableExport extends BaseExporter {
public class ImplicantTableExport extends BaseExporter {

public LogicalTruthTableExport(LogicalModel model) {
public ImplicantTableExport(LogicalModel model) {
super(model);
}

public void export() throws IOException {
MDDManager ddmanager = model.getMDDManager();
MDDVariable[] variables = ddmanager.getAllVariables();
PathSearcher searcher = new PathSearcher(ddmanager);

int[] functions = model.getLogicalFunctions();
List<NodeInfo> components = model.getComponents();

Writer writer = streams.writer();
writer.write("# Model stored as a collection of truth tables\n");
writer.write("# Logical model defined as a collection of implicant tables\n");
writer.write("# "+components+"\n\n");

RestrictedPathSearcher implicants = new RestrictedPathSearcher(ddmanager);

for (int i=0; i<components.size(); i++) {
// Truth table for component i
// Implicant table for component i
NodeInfo ni = components.get(i);
byte[] implicant = implicants.setNode(functions[i]);
int[] regulators = implicants.getRegulatorList();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.colomoto.biolqm.io.implicanttables;

import org.colomoto.biolqm.LogicalModel;
import org.colomoto.biolqm.io.AbstractFormat;
import org.colomoto.biolqm.io.LogicalModelFormat;
import org.colomoto.biolqm.service.MultivaluedSupport;
import org.kohsuke.MetaInfServices;

@MetaInfServices(LogicalModelFormat.class)
public class ImplicantTableFormat extends AbstractFormat {

public static final String ID = "itnet";

public ImplicantTableFormat() {
super(ID, "Implicant Table format", MultivaluedSupport.MULTIVALUED);
}

@Override
public ImplicantTableExport getExporter(LogicalModel model) {
return new ImplicantTableExport(model);
}


@Override
public ImplicantTableImport getLoader() {
return new ImplicantTableImport();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.colomoto.biolqm.io.truthtable;
package org.colomoto.biolqm.io.implicanttables;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CharStream;
Expand All @@ -7,8 +7,8 @@
import org.colomoto.biolqm.LogicalModelImpl;
import org.colomoto.biolqm.NodeInfo;
import org.colomoto.biolqm.io.BaseLoader;
import org.colomoto.biolqm.io.antlr.LTTLexer;
import org.colomoto.biolqm.io.antlr.LTTParser;
import org.colomoto.biolqm.io.antlr.ITNETLexer;
import org.colomoto.biolqm.io.antlr.ITNETParser;
import org.colomoto.biolqm.io.antlr.ErrorListener;
import org.colomoto.mddlib.MDDManager;
import org.colomoto.mddlib.MDDManagerFactory;
Expand All @@ -20,27 +20,27 @@
import java.util.Map;


public class LogicalTruthTableImport extends BaseLoader {
public class ImplicantTableImport extends BaseLoader {

@Override
protected LogicalModel performTask() throws Exception {

CharStream input = new ANTLRInputStream(streams.reader());
CommonTokenStream tokens = new CommonTokenStream( new LTTLexer(input) );
LTTParser parser = new LTTParser( tokens );
CommonTokenStream tokens = new CommonTokenStream( new ITNETLexer(input) );
ITNETParser parser = new ITNETParser( tokens );
ErrorListener errors = new ErrorListener();
parser.addErrorListener(errors);
LTTParser.ModelContext mtx = parser.model();
ITNETParser.ModelContext mtx = parser.model();

// Peak forward to create all components and prepare the MDD manager
List<LTTParser.TableContext> tables = mtx.table();
List<ITNETParser.TableContext> tables = mtx.table();
int nbvar = tables.size();
List<NodeInfo> components = new ArrayList<>(nbvar);
Map<String,Integer> id2index = new HashMap<>();
MDDVariableFactory mvf = new MDDVariableFactory();
int max = 5;
for (int idx=0 ; idx<nbvar ; idx++) {
LTTParser.TableContext ttx = tables.get(idx);
ITNETParser.TableContext ttx = tables.get(idx);
String id = ttx.curvar().getText();
id2index.put(id, idx);
byte curmax = 1;
Expand All @@ -61,27 +61,27 @@ protected LogicalModel performTask() throws Exception {

// Load all functions
int[] functions = new int[nbvar];
for (LTTParser.TableContext ttx: mtx.table()) {
for (ITNETParser.TableContext ttx: mtx.table()) {
int curComponent = id2index.get( ttx.curvar().getText() );
List<LTTParser.VarContext> regulatorIDs = ttx.var();
List<ITNETParser.VarContext> regulatorIDs = ttx.var();
int[] regulators = new int[regulatorIDs.size()];
int i = 0;
for (LTTParser.VarContext vtx: regulatorIDs) {
for (ITNETParser.VarContext vtx: regulatorIDs) {
regulators[i++] = id2index.get(vtx.getText());
}

List<LTTParser.LineContext> ttlines = ttx.line();
List<ITNETParser.LineContext> ttlines = ttx.line();
List<byte[]> states = new ArrayList<>( ttlines.size());
int count = regulators.length;
for (LTTParser.LineContext ltx: ttlines) {
for (ITNETParser.LineContext ltx: ttlines) {
int targetValue = Integer.parseInt( ltx.target().getText() );
if (targetValue == 0) {
continue;
}

String line = ltx.ttline().getText().trim();
if (line.length() != count) {
throw new RuntimeException("Wrong number of values in truth table line: "+line.length() +" expected "+ count);
throw new RuntimeException("Wrong number of values in implicant table line: "+line.length() +" expected "+ count);
}

byte[] vals = new byte[count];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Implicant table format.
* This package contains import/export support for models defined as a list of implicant tables.
*/
package org.colomoto.biolqm.io.implicanttables;

This file was deleted.

0 comments on commit 9e20f45

Please sign in to comment.