Move verification back into iBioSim.

Update the scripts
Update version to 3.0.0-SNAPSHOT
This commit is contained in:
Chris Myers 2017-07-05 16:13:44 -06:00
parent 3ec61f5f43
commit b2d240f816
195 changed files with 108574 additions and 25 deletions

View file

@ -6,7 +6,7 @@
<parent>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<packaging>jar</packaging>
@ -65,8 +65,7 @@
<dependency>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim-dataModels</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>

View file

@ -12,7 +12,5 @@
@rem
@rem ***************************************************************************
setlocal ENABLEDELAYEDEXPANSION
set CLASSPATH="%BIOSIM%\gui\dist\classes"
for /f %%a IN ('dir /b "%BIOSIM%\gui\lib\*.jar"') do call set CLASSPATH=!CLASSPATH!;"%BIOSIM%\gui\lib\%%a"
java -Xmx2048M -Xms2048M -XX:+UseSerialGC -classpath %CLASSPATH% main.Gui
java -Xmx2048M -Xms2048M -XX:+UseSerialGC -jar iBioSim.jar

View file

@ -8,7 +8,9 @@ fi
if [ -z "$BIOSIM" ]; then
export BIOSIM=$PWD/..
fi
export PATH=$BIOSIM/bin:$PATH
export LD_LIBRARY_PATH=$BIOSIM/lib64:$LD_LIBRARY_PATH
export DDLD_LIBRARY_PATH=$BIOSIM/lib64:$DDLD_LIBRARY_PATH
exec java -Xmx2048M -Xms2048M -XX:+UseSerialGC -jar iBioSim.jar
export PATH=$BIOSIM/bin:/usr/local/lib:$PATH
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export DDLD_LIBRARY_PATH=/usr/local/lib:$DDLD_LIBRARY_PATH
exec java -Xmx2048M -Xms2048M -XX:+UseSerialGC -Djava.library.path=/usr/local/lib -jar iBioSim.jar

View file

@ -6,7 +6,7 @@
<parent>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<packaging>jar</packaging>
@ -120,7 +120,7 @@
<dependency>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim-dataModels</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>uk.ac.ncl.ico2s</groupId>

View file

@ -6,7 +6,7 @@
<parent>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<packaging>jar</packaging>

View file

@ -6,7 +6,7 @@
<parent>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<packaging>jar</packaging>
@ -203,31 +203,31 @@
<dependency>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim-dataModels</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim-conversion</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim-learn</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim-analysis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim-synthesis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>

View file

@ -5,7 +5,7 @@
<artifactId>iBioSim-learn</artifactId>
<parent>
<groupId>edu.utah.ece.async</groupId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
<artifactId>iBioSim</artifactId>
</parent>
@ -15,7 +15,7 @@
<dependency>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim-analysis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View file

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>iBioSim</name>
<description>CAD tool aimed for the modeling, analysis, and design of genetic circuits. This tool supports both SBML and SBOL data models.</description>
@ -36,6 +36,7 @@
<module>gui</module>
<module>synthesis</module>
<module>learn</module>
<module>verification</module>
</modules>
<build>

View file

@ -6,7 +6,7 @@
<parent>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<packaging>jar</packaging>
@ -14,8 +14,7 @@
<dependency>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim-dataModels</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
<version>3.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

1
verification/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target/

21
verification/pom.xml Normal file
View file

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>LEMA-verification</artifactId>
<parent>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim</artifactId>
<version>3.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>edu.utah.ece.async</groupId>
<artifactId>iBioSim-dataModels</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View file

@ -0,0 +1,39 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification;
import java.io.File;
import java.io.FileFilter;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class FileExtentionFilter implements FileFilter {
private final String extension;
FileExtentionFilter(String extenstion) {
this.extension = extenstion;
}
@Override
public boolean accept(File pathname) {
return pathname.getPath().toLowerCase().endsWith(extension);
}
}

View file

@ -0,0 +1,173 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification;
import java.io.File;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import edu.utah.ece.async.ibiosim.dataModels.util.GlobalConstants;
import edu.utah.ece.async.ibiosim.dataModels.util.exceptions.BioSimException;
import edu.utah.ece.async.lema.verification.lpn.LPN;
import edu.utah.ece.async.lema.verification.platu.main.Options;
import edu.utah.ece.async.lema.verification.platu.project.Project;
/**
* This class provides script to run depth-first search and partial order reduction (in the platu package)
* without the need for a GUI.
*
* @author Zhen Zhang
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class VerificationCommandLine {
static String separator = GlobalConstants.separator;
public static void main (String[] args) {
if (args.length == 0) {
System.err.println("Error: Missing arguments.");
System.exit(0);
}
String directory = null;
File dir = null;
ArrayList<LPN> lpnList = new ArrayList<LPN>();
ArrayList<String> lpnNames = new ArrayList<String>();
boolean allLPNs = false;
for (int i=0; i<args.length; i++) {
switch (args[i].charAt(0)) {
case '-': // options
if (args[i].length() < 2)
throw new IllegalArgumentException("Not a valid argument: "+args[i]);
if (args[i].equals("-portb")) {
Options.setPOR("tb");
Options.setCycleClosingMthd("behavioral");
Options.setCycleClosingStrongStubbornMethd("cctb");
}
else if (args[i].equals("-porbehavioral")) {
Options.setPOR("behavioral");
Options.setCycleClosingMthd("behavioral");
Options.setCycleClosingStrongStubbornMethd("cctboff");
}
else if (args[i].equals("-portboff")) {
Options.setPOR("tboff");
Options.setCycleClosingMthd("behavioral");
Options.setCycleClosingStrongStubbornMethd("cctboff");
}
// Directory should be provided as an argument starting with -dir.
else if (args[i].contains("-dir=")) {
directory = args[i].trim().substring(5);
}
// Runtime, memory usage, and state count etc are written in the log file specified here.
else if (args[i].contains("-log=")) {
Options.setLogName(args[i].trim().substring(5));
}
// else if (args[i].contains("-memlim=")) {
// Options.setMemUpperBoundFlag();
// String memUpperBound = args[i].trim().replace("-memlim=", "");
// if(memUpperBound.contains("G")) {
// memUpperBound = memUpperBound.replace("G", "");
// Options.setMemoryUpperBound((long)(Float.parseFloat(memUpperBound) * 1000000000));
// }
// if(memUpperBound.contains("M")) {
// memUpperBound = memUpperBound.replace("M", "");
// Options.setMemoryUpperBound((long)(Float.parseFloat(memUpperBound) * 1000000));
// }
// }
//
else if (args[i].contains("-allLPNs")) {
allLPNs = true;
}
else if (args[i].contains("-db")) {
Options.setDebugMode(true);
System.out.println("Debug mode is ON.");
}
// else if (args[i].contains("-depQueue")) {
// Options.setUseDependentQueue();
// System.out.println("Use dependent queue.");
// }
else if (args[i].contains("-disableDisablingError")) {
Options.disableDisablingError();
System.out.println("Disabling error was diabled.");
}
else if (args[i].contains("-sg")) {
Options.setOutputSgFlag(true);
System.out.println("Gererate state graphs.");
}
else if (args[i].contains("-prob")) {
Options.setMarkovianModelFlag();
System.out.println("Probabilistic LPNs.");
}
break;
default: // input LPN file(s)
if (!args[i].endsWith(".lpn")) {
throw new IllegalArgumentException("Not a valid input LPN: "+args[i]);
}
lpnNames.add(args[i]);
break;
}
}
if (directory != null) {
dir = new File(directory);
if (!dir.exists()) {
System.err.println("Invalid direcotry. Exit.");
System.exit(0);
}
}
else {
directory = System.getProperty("user.dir");
dir = new File(directory);
System.out.println(directory);
}
Options.setPrjSgPath(directory);
// Options for printing the final numbers from search_dfs or search_dfsPOR.
Options.setOutputLogFlag(true);
// If the "-allLPNs" option exists, then all LPNs under a directory (either specified by "-dir" or
// the current directory by default) are considered. If this option is followed by user specified LPNs, they
// get ignored.
try {
if (allLPNs) {
File[] lpns = dir.listFiles(new FileExtentionFilter(".lpn"));
lpnList.clear();
for (int i=0; i < lpns.length; i++) {
String curLPNname = lpns[i].getName();
LPN curLPN = new LPN();
curLPN.load(directory + separator + curLPNname);
lpnList.add(curLPN);
}
}
else {
for (int i=0; i < lpnNames.size(); i++) {
LPN curLPN = new LPN();
curLPN.load(directory + separator + lpnNames.get(i));//load(directory + curLPNname);
lpnList.add(curLPN);
}
}
} catch (BioSimException e) {
e.printStackTrace();
}
System.out.println("====== LPN loading order ========");
for (int i=0; i<lpnList.size(); i++) {
System.out.println(lpnList.get(i).getLabel());
}
Project untimed_dfs = new Project(lpnList);
try {
untimed_dfs.search();
} catch (BioSimException e) {
e.printStackTrace();
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,626 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
/* Generated By:JavaCC: Do not edit this line. JavaCharStream.java Version 5.0 */
/* JavaCCOptions:STATIC=false,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package edu.utah.ece.async.lema.verification.lpn;
/**
* An implementation of interface CharStream, where the stream is assumed to
* contain only ASCII characters (with java-like unicode escape processing).
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public
class JavaCharStream
{
/** Whether parser is static. */
public static final boolean staticFlag = false;
static final int hexval(char c) throws java.io.IOException {
switch(c)
{
case '0' :
return 0;
case '1' :
return 1;
case '2' :
return 2;
case '3' :
return 3;
case '4' :
return 4;
case '5' :
return 5;
case '6' :
return 6;
case '7' :
return 7;
case '8' :
return 8;
case '9' :
return 9;
case 'a' :
case 'A' :
return 10;
case 'b' :
case 'B' :
return 11;
case 'c' :
case 'C' :
return 12;
case 'd' :
case 'D' :
return 13;
case 'e' :
case 'E' :
return 14;
case 'f' :
case 'F' :
return 15;
}
throw new java.io.IOException(); // Should never come here
}
/** Position in buffer. */
public int bufpos = -1;
int bufsize;
int available;
int tokenBegin;
protected int bufline[];
protected int bufcolumn[];
protected int column = 0;
protected int line = 1;
protected boolean prevCharIsCR = false;
protected boolean prevCharIsLF = false;
protected java.io.Reader inputStream;
protected char[] nextCharBuf;
protected char[] buffer;
protected int maxNextCharInd = 0;
protected int nextCharInd = -1;
protected int inBuf = 0;
protected int tabSize = 8;
protected void setTabSize(int i) { tabSize = i; }
protected int getTabSize() { return tabSize; }
protected void ExpandBuff(boolean wrapAround)
{
char[] newbuffer = new char[bufsize + 2048];
int newbufline[] = new int[bufsize + 2048];
int newbufcolumn[] = new int[bufsize + 2048];
try
{
if (wrapAround)
{
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos);
buffer = newbuffer;
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
bufline = newbufline;
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
bufcolumn = newbufcolumn;
bufpos += (bufsize - tokenBegin);
}
else
{
System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
buffer = newbuffer;
System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
bufline = newbufline;
System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
bufcolumn = newbufcolumn;
bufpos -= tokenBegin;
}
}
catch (Throwable t)
{
throw new Error(t.getMessage());
}
available = (bufsize += 2048);
tokenBegin = 0;
}
protected void FillBuff() throws java.io.IOException
{
int i;
if (maxNextCharInd == 4096)
maxNextCharInd = nextCharInd = 0;
try {
if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
4096 - maxNextCharInd)) == -1)
{
inputStream.close();
throw new java.io.IOException();
}
maxNextCharInd += i;
return;
}
catch(java.io.IOException e) {
if (bufpos != 0)
{
--bufpos;
backup(0);
}
else
{
bufline[bufpos] = line;
bufcolumn[bufpos] = column;
}
throw e;
}
}
protected char ReadByte() throws java.io.IOException
{
if (++nextCharInd >= maxNextCharInd)
FillBuff();
return nextCharBuf[nextCharInd];
}
/** @return starting character for token. */
public char BeginToken() throws java.io.IOException
{
if (inBuf > 0)
{
--inBuf;
if (++bufpos == bufsize)
bufpos = 0;
tokenBegin = bufpos;
return buffer[bufpos];
}
tokenBegin = 0;
bufpos = -1;
return readChar();
}
protected void AdjustBuffSize()
{
if (available == bufsize)
{
if (tokenBegin > 2048)
{
bufpos = 0;
available = tokenBegin;
}
else
ExpandBuff(false);
}
else if (available > tokenBegin)
available = bufsize;
else if ((tokenBegin - available) < 2048)
ExpandBuff(true);
else
available = tokenBegin;
}
protected void UpdateLineColumn(char c)
{
column++;
if (prevCharIsLF)
{
prevCharIsLF = false;
line += (column = 1);
}
else if (prevCharIsCR)
{
prevCharIsCR = false;
if (c == '\n')
{
prevCharIsLF = true;
}
else
line += (column = 1);
}
switch (c)
{
case '\r' :
prevCharIsCR = true;
break;
case '\n' :
prevCharIsLF = true;
break;
case '\t' :
column--;
column += (tabSize - (column % tabSize));
break;
default :
break;
}
bufline[bufpos] = line;
bufcolumn[bufpos] = column;
}
/** Read a character. */
public char readChar() throws java.io.IOException
{
if (inBuf > 0)
{
--inBuf;
if (++bufpos == bufsize)
bufpos = 0;
return buffer[bufpos];
}
char c;
if (++bufpos == available)
AdjustBuffSize();
if ((buffer[bufpos] = c = ReadByte()) == '\\')
{
UpdateLineColumn(c);
int backSlashCnt = 1;
for (;;) // Read all the backslashes
{
if (++bufpos == available)
AdjustBuffSize();
try
{
if ((buffer[bufpos] = c = ReadByte()) != '\\')
{
UpdateLineColumn(c);
// found a non-backslash char.
if ((c == 'u') && ((backSlashCnt & 1) == 1))
{
if (--bufpos < 0)
bufpos = bufsize - 1;
break;
}
backup(backSlashCnt);
return '\\';
}
}
catch(java.io.IOException e)
{
// We are returning one backslash so we should only backup (count-1)
if (backSlashCnt > 1)
backup(backSlashCnt-1);
return '\\';
}
UpdateLineColumn(c);
backSlashCnt++;
}
// Here, we have seen an odd number of backslash's followed by a 'u'
try
{
while ((c = ReadByte()) == 'u')
++column;
buffer[bufpos] = c = (char)(hexval(c) << 12 |
hexval(ReadByte()) << 8 |
hexval(ReadByte()) << 4 |
hexval(ReadByte()));
column += 4;
}
catch(java.io.IOException e)
{
throw new Error("Invalid escape character at line " + line +
" column " + column + ".");
}
if (backSlashCnt == 1)
return c;
backup(backSlashCnt - 1);
return '\\';
}
UpdateLineColumn(c);
return c;
}
@Deprecated
/**
* @deprecated
* @see #getEndColumn
*/
public int getColumn() {
return bufcolumn[bufpos];
}
@Deprecated
/**
* @deprecated
* @see #getEndLine
*/
public int getLine() {
return bufline[bufpos];
}
/** Get end column. */
public int getEndColumn() {
return bufcolumn[bufpos];
}
/** Get end line. */
public int getEndLine() {
return bufline[bufpos];
}
/** @return column of token start */
public int getBeginColumn() {
return bufcolumn[tokenBegin];
}
/** @return line number of token start */
public int getBeginLine() {
return bufline[tokenBegin];
}
/** Retreat. */
public void backup(int amount) {
inBuf += amount;
if ((bufpos -= amount) < 0)
bufpos += bufsize;
}
/** Constructor. */
public JavaCharStream(java.io.Reader dstream,
int startline, int startcolumn, int buffersize)
{
inputStream = dstream;
line = startline;
column = startcolumn - 1;
available = bufsize = buffersize;
buffer = new char[buffersize];
bufline = new int[buffersize];
bufcolumn = new int[buffersize];
nextCharBuf = new char[4096];
}
/** Constructor. */
public JavaCharStream(java.io.Reader dstream,
int startline, int startcolumn)
{
this(dstream, startline, startcolumn, 4096);
}
/** Constructor. */
public JavaCharStream(java.io.Reader dstream)
{
this(dstream, 1, 1, 4096);
}
/** Reinitialise. */
public void ReInit(java.io.Reader dstream,
int startline, int startcolumn, int buffersize)
{
inputStream = dstream;
line = startline;
column = startcolumn - 1;
if (buffer == null || buffersize != buffer.length)
{
available = bufsize = buffersize;
buffer = new char[buffersize];
bufline = new int[buffersize];
bufcolumn = new int[buffersize];
nextCharBuf = new char[4096];
}
prevCharIsLF = prevCharIsCR = false;
tokenBegin = inBuf = maxNextCharInd = 0;
nextCharInd = bufpos = -1;
}
/** Reinitialise. */
public void ReInit(java.io.Reader dstream,
int startline, int startcolumn)
{
ReInit(dstream, startline, startcolumn, 4096);
}
/** Reinitialise. */
public void ReInit(java.io.Reader dstream)
{
ReInit(dstream, 1, 1, 4096);
}
/** Constructor. */
public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
{
this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
}
/** Constructor. */
public JavaCharStream(java.io.InputStream dstream, int startline,
int startcolumn, int buffersize)
{
this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
}
/** Constructor. */
public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
int startcolumn) throws java.io.UnsupportedEncodingException
{
this(dstream, encoding, startline, startcolumn, 4096);
}
/** Constructor. */
public JavaCharStream(java.io.InputStream dstream, int startline,
int startcolumn)
{
this(dstream, startline, startcolumn, 4096);
}
/** Constructor. */
public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
{
this(dstream, encoding, 1, 1, 4096);
}
/** Constructor. */
public JavaCharStream(java.io.InputStream dstream)
{
this(dstream, 1, 1, 4096);
}
/** Reinitialise. */
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
{
ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
}
/** Reinitialise. */
public void ReInit(java.io.InputStream dstream, int startline,
int startcolumn, int buffersize)
{
ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
}
/** Reinitialise. */
public void ReInit(java.io.InputStream dstream, String encoding, int startline,
int startcolumn) throws java.io.UnsupportedEncodingException
{
ReInit(dstream, encoding, startline, startcolumn, 4096);
}
/** Reinitialise. */
public void ReInit(java.io.InputStream dstream, int startline,
int startcolumn)
{
ReInit(dstream, startline, startcolumn, 4096);
}
/** Reinitialise. */
public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
{
ReInit(dstream, encoding, 1, 1, 4096);
}
/** Reinitialise. */
public void ReInit(java.io.InputStream dstream)
{
ReInit(dstream, 1, 1, 4096);
}
/** @return token image as String */
public String GetImage()
{
if (bufpos >= tokenBegin)
return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
return new String(buffer, tokenBegin, bufsize - tokenBegin) +
new String(buffer, 0, bufpos + 1);
}
/** @return suffix */
public char[] GetSuffix(int len)
{
char[] ret = new char[len];
if ((bufpos + 1) >= len)
System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
else
{
System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
len - bufpos - 1);
System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
}
return ret;
}
/** Set buffers back to null when finished. */
public void Done()
{
nextCharBuf = null;
buffer = null;
bufline = null;
bufcolumn = null;
}
/**
* Method to adjust line and column numbers for the start of a token.
*/
public void adjustBeginLineColumn(int newLine, int newCol)
{
int start = tokenBegin;
int len;
if (bufpos >= tokenBegin)
{
len = bufpos - tokenBegin + inBuf + 1;
}
else
{
len = bufsize - tokenBegin + bufpos + 1 + inBuf;
}
int i = 0, j = 0, k = 0;
int nextColDiff = 0, columnDiff = 0;
while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
{
bufline[j] = newLine;
nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
bufcolumn[j] = newCol + columnDiff;
columnDiff = nextColDiff;
i++;
}
if (i < len)
{
bufline[j] = newLine++;
bufcolumn[j] = newCol + columnDiff;
while (i++ < len)
{
if (bufline[j = start % bufsize] != bufline[++start % bufsize])
bufline[j] = newLine++;
else
bufline[j] = newLine;
}
}
line = bufline[j];
column = bufcolumn[j];
}
}
/* JavaCC - OriginalChecksum=d8bc55bac4472bc0df907ee2abfc3dd4 (do not edit this line) */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,665 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn;
import java.io.*;
import java.util.*;
import edu.utah.ece.async.ibiosim.dataModels.util.GlobalConstants;
import edu.utah.ece.async.ibiosim.dataModels.util.exceptions.BioSimException;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Lpn2verilog {
//String place;
public static void convert(String lpnFileName) throws BioSimException {
HashMap<String,Boolean> visitedPlaces;
String enable = "";
String separator = GlobalConstants.separator;
try{
LPN lpn = new LPN();
lpn.load(lpnFileName);
String svFileName = lpnFileName.replaceAll(".lpn", ".sv");
File svFile = new File(svFileName);
svFile.createNewFile();
String[] svPath = svFileName.split(separator);
//for (int i=0; i < svPath.length; i++){
//System.out.println("\nModule string is " + svPath[i] + "\n");}
String svModuleName = svPath[svPath.length -1].split("\\.")[0];
//System.out.println("\nModule name is " + svModuleName + "\n");
BufferedWriter sv = new BufferedWriter(new FileWriter(svFile));
StringBuffer initBuffer = new StringBuffer();
StringBuffer markedPlaceBuffer = new StringBuffer();
StringBuffer assertionBuffer = new StringBuffer();
sv.write("`timescale 1ps/1fs\n\n"); //TODO: THIS IS ASSUMPTION
Boolean first = true;
String[] varsList = lpn.getVariables();
sv.write("module "+svModuleName + " (");
for (String v: varsList){
if (lpn.isOutput(v)){
if (first){
if (lpn.isInteger(v) || lpn.isContinuous(v)){
sv.write("output real " + v); //TODO: Integer if dmv?
} else{
sv.write("output logic " + v);
}
first = false;
} else{
if (lpn.isInteger(v) || lpn.isContinuous(v)){
sv.write(", output real " + v);
} else{
sv.write(", output logic " + v);
}
}
}
else if (lpn.isInput(v)){
if (first){
if (lpn.isInteger(v) || lpn.isContinuous(v)){
sv.write("input real " + v);//svFileName.split("\\.")[0]+
} else{
sv.write("input wire " + v);//svFileName.split("\\.")[0]+
}
first = false;
} else{
if (lpn.isInteger(v) || lpn.isContinuous(v)){
sv.write(", input real " + v);
} else{
sv.write(", input wire " + v);
}
}
}
//else deal with inout and internal
}
sv.write(");\n");
first = true;
String[] transitionList = lpn.getTransitionList();
ArrayList<String> transArrayList = new ArrayList<String>(Arrays.asList(transitionList));
//System.out.println("\ntransArray list is " + transArrayList + "\n");
Collections.sort(transArrayList,new Comparator<String>(){
@Override
public int compare(String a, String b){
return(a.compareToIgnoreCase(b));
}
});
transArrayList.toArray(transitionList);
String[] placeList = lpn.getPlaceList();
ArrayList<String> placeArrayList = new ArrayList<String>(Arrays.asList(placeList));
Collections.sort(placeArrayList,new Comparator<String>(){
@Override
public int compare(String a, String b){
return(a.compareToIgnoreCase(b));
}
});
placeArrayList.toArray(placeList);
initBuffer.append("\t\t$dumpfile(\"" + svModuleName + ".vcd\");\n");
initBuffer.append("\t\t$dumpvars(0," + svModuleName + ");\n");
for (String st: transitionList){
if (lpn.getTransition(st).isPersistent()){
if (first){
sv.write("\treg " + st+"p");
first = false;
} else{
sv.write(", " + st);
}
//}
if (!first){
sv.write(";\n");
}
//}
first = true;
}
}
first = true;
for (String st: transitionList){
//if (!lpn.getTransition(st).isPersistent() || lpn.getTransition(st).hasConflictSet()){
if (first){//System.out.println("This is a non- persistent Transition :"+st);
sv.write("\twire " + st);
first = false;
} else{
sv.write(", " + st);
}
//}
}
if (!first){
sv.write(";\n");
}
first = true;
for (String v: varsList){
if (!lpn.isInput(v) && !lpn.isOutput(v) && !lpn.isContinuous(v)){
if (first){
first = false;
sv.write("\treal " + v);
}
else
sv.write("," + v);
}
else
if (lpn.isContinuous(v)){
if(first){
first = false;
sv.write("\treal "+v+", rate_"+v);
}
else sv.write(","+v+", rate_"+v);
}
//else {}
//sv.write("," + v);
}
if (!first)
sv.write(";\n");
//initBuffer.append(";\n");
HashMap<String,Integer> tag = new HashMap<String,Integer>();
visitedPlaces = new HashMap<String,Boolean>();
int netCount = 0;
first = true;
for (String v2: varsList){boolean contiCounter = false;
if(lpn.isContinuous(v2)){
if (!contiCounter){
initBuffer.append("\t\t reset = 1; \n"); contiCounter= true;
}
String initRate = lpn.getInitialRate(v2);
initRate = initRate.replace("[","uniform(");
initRate = initRate.replace("]",")");
//System.out.println("initRate = "+initRate);
initBuffer.append("\t\t rate_"+v2+" = "+initRate+";\n");
String initValue = lpn.getInitialVal(v2);
initValue = initValue.replace("[","uniform(");
initValue = initValue.replace("]",")");
initBuffer.append("\t\t"+v2+" ="+initValue+";\n");
}
else {
String initValue = lpn.getInitialVal(v2);
initValue = initValue.replace("[","uniform(");
initValue = initValue.replace("]",")");
initBuffer.append("\t\t"+v2+" ="+initValue+";\n");
}
}
for (String st: placeList){
if (first){
sv.write("\tlogic " + st);
if (lpn.getPlace(st).isMarked()){
initBuffer.append("\t\t" + st + " = 0");
if (markedPlaceBuffer.length() == 0)
markedPlaceBuffer.append("\t\t#1;\n");
markedPlaceBuffer.append("\t\t" + st + " = 1; //Initially Marked\n");
tag = tagNet(lpn,st,netCount,tag,visitedPlaces);
netCount++;
}
else
initBuffer.append("\t\t" + st + " = 0");
first = false;
} else{
sv.write(", " + st);
if (lpn.getPlace(st).isMarked()){
initBuffer.append("; " + st + " = 0");
if (markedPlaceBuffer.length() == 0)
markedPlaceBuffer.append("\t\t#1;\n");
markedPlaceBuffer.append("\t\t" + st + " = 1; //Initially Marked\n");
tagNet(lpn,st,netCount,tag,visitedPlaces);
netCount++;
}
else
initBuffer.append("; " + st + " = 0");
}
if (lpn.getPreset(st) == null){
//TODO: traverse all the non-repeating transitions from here and assign a tag to them
}
}
for (String v1: varsList){
if(lpn.isContinuous(v1)){
sv.write(", fastClk,reset");
break;
}
} //new code
if (!first)
sv.write(";\n");
if (!first){
initBuffer.append(";\n");
initBuffer.append(markedPlaceBuffer);
}
boolean firstCont = true;
for (String v: varsList){
if ((v != null) && (lpn.isOutput(v))){ //Initialize only outputs. Inputs will be initialized in their driver modules. Null condition Not Required ??
//String initVal = lpn.getInitialVal(v);
if (lpn.isContinuous(v) || lpn.isInteger(v)){
if (lpn.isContinuous(v)){
// TODO: Call Verilog-AMS generation from here. No System Verilog in this case
//double initRate = Double.parseDouble(lpn.getInitialRate(v));
if (firstCont){
firstCont = false;
// initBuffer.append("\t\tentryTime<=$time;\n");
// sv.write("\treal entryTime;\n");
}
//sv.write("\treal rate_" + v + ", change_" + v + ";\n");
if ((lpn.getInitialRate(v) != null) && (!lpn.getInitialRate(v).equalsIgnoreCase("unknown"))){
//String initBufferString = getInitBufferString(v, lpn.getInitialRate(v));
//initBuffer.append("\t\trate_" + initBufferString);
}
if ((lpn.getInitialVal(v) != null) && (!lpn.getInitialVal(v).equalsIgnoreCase("unknown"))){
//String initBufferString = getInitBufferString(v, lpn.getInitialVal(v));
// initBuffer.append("\t\tchange_" + initBufferString);
}
} else {
if ((lpn.getInitialVal(v) != null) && (!lpn.getInitialVal(v).equalsIgnoreCase("unknown"))){
String initBufferString = getInitBufferString(v, lpn.getInitialVal(v));
initBuffer.append("\t\t" + initBufferString);
}
}
}
else { // boolean variable
String initValue = lpn.getInitialVal(v);
if (initValue.equals("true")){
initBuffer.append("\t\t" + v + " = 1'b1;\n");
}
else if (initValue.equals("false")){
initBuffer.append("\t\t" + v + " = 1'b0;\n");
}
else {
//System.out.println("WARNING: The initial value of Boolean variable " + v + " should be a boolean value.");
}
}
}
}
sv.write("\tinitial begin\n");
sv.write(initBuffer.toString());
for (String v1: varsList){
if(lpn.isContinuous(v1)){
sv.write("\t\treset = 0;\n");
sv.write("\tend\n\n");
sv.write("\talways #1 fastClk = (~fastClk)&(~reset); \n\n");
break;
}
}
for (String v1: varsList){
if(lpn.isContinuous(v1)){
sv.write("\talways @(fastClk) begin \n");
sv.write("\t"+v1+" <="+v1+"+rate_"+v1+";\n");
sv.write("\tend \n\n");
//break;
}
} //new code
//sv.write("\tend\n");
int contiCounter =0 ;
for(String v1 :varsList){
if (lpn.isContinuous(v1)){
contiCounter++;
}
}
if (contiCounter ==0) sv.write("\t\t end \n\n");
Boolean[] firstTransition = new Boolean[netCount];
//StringBuffer[] alwaysBuffer = new StringBuffer[netCount];
// StringBuffer[] prioritiesBuffer = new StringBuffer[netCount];
StringBuffer[] assignmentsBuffer = new StringBuffer[netCount];
for (int j = 0; j < netCount; j++){ //System.out.println("Netcount is :"+netCount);
firstTransition[j] = true;
// alwaysBuffer[j] = new StringBuffer(); dec 4,2010
// prioritiesBuffer[j] = new StringBuffer();
assignmentsBuffer[j] = new StringBuffer();
}
for (String st : transitionList){
if (!lpn.getTransition(st).isPersistent()){ // System.out.println("This is a Non-Peristent transition : "+st);
//if (transitionList.)
sv.write("\tassign ");
ExprTree delayTree = lpn.getTransition(st).getDelayTree();
//System.out.println("Delay Tree :"+delayTree+"for transition :"+st);
if (delayTree != null){
String delay = delayTree.getElement("Verilog");
//System.out.println("Delay "+delay);
if (delay.contains("uniform")){ //range
delay = delay.replaceFirst("uniform\\(", "");
delay = delay.substring(0, delay.length()-1); //delay = delay.replace("\\)", "");
} else {
delay = delay + "," + delay;
}
sv.write("#(delay(~" + st + "," + delay + ")) " + st + " = ");
} else{
sv.write(st + " = ");
}
if (lpn.getPreset(st).length != 0){ //Assuming there's no transition without a preset.
first = true;
for (String st2 : lpn.getPreset(st)){ //System.out.println("getPreset :"+st2);
if (first){
sv.write(st2);
first = false;
}
else{
sv.write(" && " + st2);
}
}
if (lpn.getEnablingTree(st) != null){
//System.out.println("enabling");
sv.write(" && (" + lpn.getEnablingTree(st).getElement("Verilog") + ")");
//System.out.println(st +" enabling " + lpn.getEnablingTree(st).getElement("Verilog"));
}
}
sv.write(";\n");
if (lpn.getTransition(st).isFail()){
assertionBuffer.append("\talways @(" + st + ") begin\n");
assertionBuffer.append("\t\tassert(!" + st + ")\n");
assertionBuffer.append("\t\telse\n");
assertionBuffer.append("\t\t\t$error(\"Error! Assertion " + st + " failed at time %t\",$time);\n\tend\n");
} else {
assignmentsBuffer[tag.get(st)].append("\talways @(posedge " + st + ") begin\n"); //dec 4, 2010
for (String st2 : lpn.getPreset(st)){//System.out.println(" tag.get(st) :"+tag.get(st));
assignmentsBuffer[tag.get(st)].append("\t\t" + st2 + " <= 0;\n");
}
for (String st2 : lpn.getPostset(st)){
assignmentsBuffer[tag.get(st)].append("\t\t" + st2 + " <= 1;\n");
}
HashMap<String,ExprTree> assignmentTrees = lpn.getTransition(st).getAssignTrees();
HashMap<String,ExprTree> rateAssignmentTrees = lpn.getTransition(st).getRateAssignTrees();
HashMap<String,ExprTree> valueAssignmentTrees = lpn.getTransition(st).getIntAssignTrees();
HashMap<String,ExprTree> contAssignmentTrees = lpn.getTransition(st).getContAssignTrees(); //System.out.println("assignmentTrees.size() :"+assignmentTrees);
if (assignmentTrees.size() != 0){
for (String st2 : valueAssignmentTrees.keySet()){
//System.out.println("Assignment " + st2 + " <= " + lpn.getTransition(st).getAssignTree(st2));
String asgnmt = valueAssignmentTrees.get(st2).getElement("Verilog");
//System.out.println("asgnmt :"+asgnmt);
if ((asgnmt != null) && (asgnmt != ""))
assignmentsBuffer[tag.get(st)].append("\t\t" + st2 + " <= " + asgnmt + ";\n");
}
for (String st2 : contAssignmentTrees.keySet()){
//System.out.println("Assignment " + st2 + " <= " + lpn.getTransition(st).getAssignTree(st2));
String asgnmt = contAssignmentTrees.get(st2).getElement("Verilog");
if ((asgnmt != null) && (asgnmt != ""))
assignmentsBuffer[tag.get(st)].append("\t\t" + st2 + " <= " + asgnmt + ";\n");
}
for (String st2 : rateAssignmentTrees.keySet()){//System.out.println("st2 :"+st2);
//System.out.println("Assignment " + st2 + " <= " + lpn.getTransition(st).getAssignTree(st2));
String asgnmt = rateAssignmentTrees.get(st2).getElement("Verilog");// System.out.println("asgnmt :"+asgnmt);
if (asgnmt != null){
//assignmentsBuffer[tag.get(st)].append("\t\tentryTime <= $time;\n");
assignmentsBuffer[tag.get(st)].append("\t\trate_" + st2 + " <= " + asgnmt + ";\n");
//assignmentsBuffer[tag.get(st)].append("\t\tchange_" + st2 + " <= " + st2 + ";\n");
}
}
}
assignmentsBuffer[tag.get(st)].append("\tend\n");
}
}
else{
//if( lpn.getTransition(st).hasConflictSet()){
//int size = transitionList.length;
//System.out.println("st in conflict:"+st);
//Transition[] trans = new Transition[5];
//Transition[] conflictSet = new Transition[size];
//conflictSet = lpn.getTransition(st).getConflictSet();
//System.out.println("This is the conflict set size :"+size);
sv.write("\tassign ");
ExprTree delayTree = lpn.getTransition(st).getDelayTree();
//System.out.println("Delay Tree :"+delayTree+"for transition :"+st);
if (delayTree != null){
String delay = delayTree.getElement("Verilog");
//System.out.println("Delay "+delay);
if (delay.contains("uniform")){ //range
delay = delay.replaceFirst("uniform\\(", "");
delay = delay.substring(0, delay.length()-1); //delay = delay.replace("\\)", "");
} else {
delay = delay + "," + delay;
}
sv.write("#(delay(~" + st + "," + delay + ")) " + st + " = ");
} else{
sv.write(st + " = ");
}
if (lpn.getPreset(st).length != 0){ //Assuming there's no transition without a preset.
first = true;
for (String st2 : lpn.getPreset(st)){// System.out.println("getPreset :"+st2);
if (first){
sv.write("("+st2);
first = false;
}
else{
sv.write(" && " + st2);
}
}
sv.write(" && " +st+"p)");
//if (lpn.getEnablingTree(st) != null){
//System.out.println("enabling");
//sv.write(" && (" + lpn.getEnablingTree(st).getElement("Verilog") + ")");
// System.out.println(st +" enabling " + lpn.getEnablingTree(st).getElement("Verilog"));
//}
}
sv.write(";\n");// conflict box ends here
HashMap<String,ExprTree> assignmentTrees = lpn.getTransition(st).getAssignTrees();
HashMap<String,ExprTree> rateAssignmentTrees = lpn.getTransition(st).getRateAssignTrees();
HashMap<String,ExprTree> valueAssignmentTrees = lpn.getTransition(st).getIntAssignTrees();
HashMap<String,ExprTree> contAssignmentTrees = lpn.getTransition(st).getContAssignTrees(); //System.out.println("assignmentTrees.size() :"+assignmentTrees);
if (lpn.getEnablingTree(st) != null){
enable = lpn.getEnablingTree(st).getElement("Verilog");
//System.out.println("enabling");
//sv.write(" && (" + lpn.getEnablingTree(st).getElement("Verilog") + ")");
//System.out.println(st +" enabling " + enable);
}
for (String place : lpn.getPreset(st)){
//System.out.println("getPreset :"+place);
if (enable!=null){
assignmentsBuffer[tag.get(st)].append("\talways @(posedge ("+ enable + ") && (" +place+")) begin\n");} //dec 4, 2010//dec 4, 2010
else assignmentsBuffer[tag.get(st)].append("\talways @(posedge " +place+") begin\n");
}
//ExprTree delay = lpn.getDelayTree(st);
//System.out.println(" delay....delay :"+delay);
for (String st2 : lpn.getPreset(st)){
if (lpn.getEnablingTree(st) != null){
enable = lpn.getEnablingTree(st).getElement("Verilog");
//System.out.println(" tag.get(st) :"+tag.get(st));
assignmentsBuffer[tag.get(st)].append("\t\t" + st + "p <= (("+enable+") && "+st2+");\n");
//else assignmentsBuffer[tag.get(st)].append("\t\t" + st + "p <= "+st2+";\n");
}
else assignmentsBuffer[tag.get(st)].append("\t\t" + st + "p <= "+st2+";\n");
}
assignmentsBuffer[tag.get(st)].append("\tend\n");
// add 1 more normal always block here for persistent transition.
if (lpn.getTransition(st).isFail()){
assertionBuffer.append("\talways @(" + st + ") begin\n");
assertionBuffer.append("\t\tassert(!" + st + ")\n");
assertionBuffer.append("\t\telse\n");
assertionBuffer.append("\t\t\t$error(\"Error! Assertion " + st + " failed at time %t\",$time);\n\tend\n");
} else {
assignmentsBuffer[tag.get(st)].append("\talways @(posedge " + st + ") begin\n"); //dec 4, 2010
for (String st2 : lpn.getPreset(st)){//System.out.println(" tag.get(st) :"+tag.get(st));
assignmentsBuffer[tag.get(st)].append("\t\t" + st2 + " <= 0;\n");
}
for (String st2 : lpn.getPostset(st)){
assignmentsBuffer[tag.get(st)].append("\t\t" + st2 + " <= 1;\n");
}
//HashMap<String,ExprTree> assignmentTrees = lpn.getTransition(st).getAssignTrees();
//HashMap<String,ExprTree> rateAssignmentTrees = lpn.getTransition(st).getRateAssignTrees();
//HashMap<String,ExprTree> valueAssignmentTrees = lpn.getTransition(st).getIntAssignTrees();
//HashMap<String,ExprTree> contAssignmentTrees = lpn.getTransition(st).getContAssignTrees(); System.out.println("assignmentTrees.size() :"+assignmentTrees);
if (assignmentTrees.size() != 0){
for (String st2 : valueAssignmentTrees.keySet()){
//System.out.println("Assignment " + st2 + " <= " + lpn.getTransition(st).getAssignTree(st2));
String asgnmt = valueAssignmentTrees.get(st2).getElement("Verilog");
//System.out.println("asgnmt :"+asgnmt);
if ((asgnmt != null) && (asgnmt != ""))
assignmentsBuffer[tag.get(st)].append("\t\t" + st2 + " <= " + asgnmt + ";\n");
}
for (String st2 : contAssignmentTrees.keySet()){
//System.out.println("Assignment " + st2 + " <= " + lpn.getTransition(st).getAssignTree(st2));
String asgnmt = contAssignmentTrees.get(st2).getElement("Verilog");
if ((asgnmt != null) && (asgnmt != ""))
assignmentsBuffer[tag.get(st)].append("\t\t" + st2 + " <= " + asgnmt + ";\n");
}
for (String st2 : rateAssignmentTrees.keySet()){//System.out.println("st2 :"+st2);
//System.out.println("Assignment " + st2 + " <= " + lpn.getTransition(st).getAssignTree(st2));
String asgnmt = rateAssignmentTrees.get(st2).getElement("Verilog"); //System.out.println("asgnmt :"+asgnmt);
if (asgnmt != null){
assignmentsBuffer[tag.get(st)].append("\t\tentryTime <= $time;\n");
assignmentsBuffer[tag.get(st)].append("\t\trate_" + st2 + " <= " + asgnmt + ";\n");
assignmentsBuffer[tag.get(st)].append("\t\tchange_" + st2 + " <= " + st2 + ";\n");
}
}
}
assignmentsBuffer[tag.get(st)].append("\tend\n");
}
//}
}
}
if (transitionList.length > 0){
if (assertionBuffer.length()!= 0){
sv.write(assertionBuffer.toString());
}
for (int j = 0; j < netCount; j++){
// if ((alwaysBuffer[j] != null) && (alwaysBuffer[j].length() != 0)){ //dec 4,2010
if ((assignmentsBuffer[j] != null) && (assignmentsBuffer[j].length() != 0)){ //dec 4,2010
// alwaysBuffer[j].append(") begin\n"); // dec 4,2010
// sv.write(alwaysBuffer[j].toString()); // dec 4,2010
// sv.write(prioritiesBuffer[j].toString());
// sv.write("\t\tprMax" + j + " = pr" + j + ".max[0];\n");
// sv.write("\t\tif (prMax" + j + " == 0)\n\t\t\tprMax" + j + "=1;\n");
sv.write(assignmentsBuffer[j].toString());
// sv.write("\tend\n"); //dec 4,2010
}
}
}
sv.write("\tfunction real uniform(int a, int b);\n");
sv.write("\t\treal c;\n");
sv.write("\t\tif (a==b)\n");
sv.write("\t\t\treturn a;\n");
sv.write("\t\tif ((a>0)&&(b>0))\n");
sv.write("\t\t\tc = $urandom_range(a*1000,b*1000)/1000.0;\n");
sv.write("\t\telse\n");
sv.write("\t\t\tc = a+$urandom_range(b*1000-a*1000)/1000.0;\n");
sv.write("\t\treturn c;\n");
sv.write("\tendfunction\n");
sv.write("\tfunction real delay(bit tb, int l, int u);\n");
sv.write("\t\tif (~tb)\n\t\t\treturn 0.0;\n");
sv.write("\t\telse if (l == u)\n\t\t\treturn (u + 0.001*$urandom_range(1,100));\n");
sv.write("\t\telse return(uniform(l,u) + 0.001*$urandom_range(1,100));\n");
sv.write("\tendfunction\n");
sv.write("endmodule");
sv.close();
//}
} catch (IOException e){
e.printStackTrace();
//System.out.println("ERROR: Verilog file could not be created/written.");
}
}
private static String getInitBufferString(String v, String initValue) {
// Assign initial values/rates to continuous, discrete and boolean variables
// As per translator.java: Extract the lower and upper bounds and set the initial value to the mean.
// Anything that involves infinity, take either the lower or upper bound which is not infinity.
// If both are infinity, set to 0.
String initBufferString = null;
String tmp_initValue = initValue;
String[] subString = initValue.split(",");
String lowerBound = "0";
String upperBound = "inf";
if (tmp_initValue.contains(",")){
tmp_initValue = tmp_initValue.replaceFirst(",", "");
for (int i = 0; i<subString.length; i ++)
{
if (subString[i].contains("[")){
lowerBound = subString[i].replace("[", "");
}
else if (subString[i].contains("uniform(")){
lowerBound = subString[i].replace("uniform(", "");
}
else if(subString[i].contains("]")){
upperBound = subString[i].replace("]", "");
}
else if(subString[i].contains(")")){
upperBound = subString[i].replace(")", "");
}
}
// initial value involves infinity
if (lowerBound.contains("inf") || upperBound.contains("inf")){
if (lowerBound.contains("-inf") && upperBound.contains("inf")){
initValue = "0" ; // if [-inf,inf], initValue = 0
}
else if (lowerBound.contains("-inf") && !upperBound.contains("inf")){
initValue = upperBound; // if [-inf,a], initValue = a
}
else if (!lowerBound.contains("-inf") && upperBound.contains("inf")){
initValue = lowerBound; // if [a,inf], initValue = a
}
initBufferString = v + " = " + initValue + ";\n";
}
else { // initial value is a range, not involving infinity
if (!lowerBound.equalsIgnoreCase(upperBound)){
if (Double.valueOf(lowerBound) > 0)
initBufferString = v + " = " + lowerBound + " + $signed((($unsigned($random))%(" + upperBound + "-" + lowerBound + "+1)));\n";
else if (Double.valueOf(lowerBound) < 0)
initBufferString = v + " = " + lowerBound + " + $signed((($unsigned($random))%(" + upperBound + "+" + Math.abs(Integer.valueOf(lowerBound)) + "+1)));\n";
else
initBufferString = v + " = " + lowerBound + " + $signed((($unsigned($random))%(" + upperBound + "+1)));\n";
}
else
initBufferString = v + " = " + lowerBound + ";\n";
}
}
else { // initial rate is a single number
initBufferString = v + " = " + initValue + ";\n";
}
return(initBufferString);
}
private static HashMap<String,Integer> tagNet(LPN g, String place, int id, HashMap<String,Integer> tag,
HashMap<String,Boolean> visitedPlaces){
//System.out.println("Place is :"+place);
if (!visitedPlaces.containsKey(place)){
visitedPlaces.put(place,true);
for (String postsetTrans : g.getPostset(place)){
//System.out.println("postset : "+postsetTrans);
tag.put(postsetTrans, id);
//System.out.println("Tagged transition " + postsetTrans + " with " + id);
for (String postsetPlace : g.getPostset(postsetTrans)){// System.out.println("postsetPlace :"+postsetPlace);
tag = tagNet(g, postsetPlace, id, tag, visitedPlaces);
}
}
}
//System.out.println("Hello");
return tag;
}
}

View file

@ -0,0 +1,159 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn.LpnDecomposition;
import java.util.ArrayList;
import edu.utah.ece.async.lema.verification.lpn.LPN;
import edu.utah.ece.async.lema.verification.lpn.Place;
import edu.utah.ece.async.lema.verification.lpn.Transition;
import edu.utah.ece.async.lema.verification.lpn.Variable;
import edu.utah.ece.async.lema.verification.platu.main.Options;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Component extends LPN{
private ArrayList<Integer> processIDList;
private ArrayList<Transition> compTrans;
private ArrayList<Place> compPlaces;
private ArrayList<Variable> compInputs;
private ArrayList<Variable> compOutputs;
private ArrayList<Variable> compInternals;
private int compid;
public Component(LpnProcess process) {
compTrans = new ArrayList<Transition>();
compPlaces = new ArrayList<Place>();
processIDList = new ArrayList<Integer>();
compInputs = new ArrayList<Variable>();
compOutputs = new ArrayList<Variable>();
compInternals = new ArrayList<Variable>();
processIDList.add(process.getProcessId());
compTrans.addAll(process.getProcessTransitions());
compPlaces.addAll(process.getProcessPlaces());
compInputs.addAll(process.getProcessInput());
compOutputs.addAll(process.getProcessOutput());
compInternals.addAll(process.getProcessInternal());
compid = process.getProcessId();
}
public Component() {
compTrans = new ArrayList<Transition>();
compPlaces = new ArrayList<Place>();
processIDList = new ArrayList<Integer>();
compInputs = new ArrayList<Variable>();
compOutputs = new ArrayList<Variable>();
compInternals = new ArrayList<Variable>();
}
public Component getComponent() {
return this;
}
public Integer getComponentId() {
return compid;
}
public void setComponentId(Integer id) {
this.compid = id;
}
public ArrayList<Integer> getProcessIDList() {
return processIDList;
}
public void setProcessIDList(ArrayList<Integer> processIDList) {
this.processIDList = processIDList;
}
public ArrayList<Variable> getInternals() {
return compInternals;
}
public ArrayList<Variable> getOutputs() {
return compOutputs;
}
public ArrayList<Variable> getInputs() {
return compInputs;
}
public LPN buildLPN(LPN lpnComp) {
// Places
for (int i=0; i< this.getComponentPlaces().size(); i++) {
Place p = this.getComponentPlaces().get(i);
lpnComp.addPlace(p.getName(), p.isMarked());
}
// Transitions
for (int i=0; i< this.getCompTransitions().size(); i++) {
Transition t = this.getCompTransitions().get(i);
t.setIndex(i);
lpnComp.addTransition(t);
}
// Inputs
for (int i=0; i< this.getInputs().size(); i++) {
Variable var = this.getInputs().get(i);
lpnComp.addInput(var.getName(), var.getType(), var.getInitValue());
}
// Outputs
for (int i=0; i< this.getOutputs().size(); i++) {
Variable var = this.getOutputs().get(i);
lpnComp.addOutput(var.getName(), var.getType(), var.getInitValue());
}
// Internal
for (int i=0; i< this.getInternals().size(); i++) {
Variable var = this.getInternals().get(i);
lpnComp.addInternal(var.getName(), var.getType(), var.getInitValue());
}
return lpnComp;
}
public ArrayList<Transition> getCompTransitions() {
return compTrans;
}
public ArrayList<Place> getComponentPlaces() {
return compPlaces;
}
public int getNumVars() {
// return the number of variables in this component
if (Options.getDebugMode()) {
System.out.println("+++++++ Vars in component " + this.getComponentId() + "+++++++");
System.out.println("compInputs:");
for (int i=0; i < compInputs.size(); i++) {
System.out.println(compInputs.get(i).getName());
}
System.out.println("compOutputs:");
for (int i=0; i < compOutputs.size(); i++) {
System.out.println(compOutputs.get(i).getName());
}
System.out.println("compInternal:");
for (int i=0; i < compInternals.size(); i++) {
System.out.println(compInternals.get(i).getName());
}
System.out.println("++++++++++++++++++");
}
return compInputs.size() + compInternals.size() + compOutputs.size();
}
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn.LpnDecomposition;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Edge {
public final Vertex target;
private Integer weight;
public Edge(Vertex target) {
this.target = target;
this.weight = 0;
}
public void addWeight() {
this.weight ++ ;
}
public Integer getWeight() {
return this.weight;
}
}

View file

@ -0,0 +1,145 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn.LpnDecomposition;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.PriorityQueue;
import edu.utah.ece.async.lema.verification.lpn.Variable;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class LpnComponentGraph{
private Integer maxNumVarsInOneComp;
private HashMap<Integer, Vertex> vertices;
public LpnComponentGraph(
HashMap<Variable, ArrayList<Integer>> sharedCompVarsMap,
HashMap<Integer,Component> compMap, Integer maxNumProcInOneComp) {
this.maxNumVarsInOneComp = maxNumProcInOneComp;
vertices = new HashMap<Integer, Vertex>();
// Create a component graph. vertex = component ID. edge weights = the number of shared variables between two components.
if (sharedCompVarsMap.isEmpty() && compMap.size() == 1) {
for (Iterator<Integer> compMapIter = compMap.keySet().iterator(); compMapIter.hasNext();) {
Integer curCompId = compMapIter.next();
Vertex curVertex = new Vertex(compMap.get(curCompId).getComponentId(), maxNumProcInOneComp);
vertices.put(compMap.get(curCompId).getComponentId(), curVertex);
}
}
else {
for (ArrayList<Integer> componentIDList : sharedCompVarsMap.values()) {
for (int i=0; i<componentIDList.size(); i++) {
Vertex curVertex;
if (vertices.keySet().contains(componentIDList.get(i))) {
curVertex = vertices.get(componentIDList.get(i));
}
else {
curVertex = new Vertex(componentIDList.get(i), compMap.get(componentIDList.get(i)).getNumVars());
vertices.put(componentIDList.get(i), curVertex);
}
for (int j=0; j<componentIDList.size(); j++) {
if (i != j) {
Vertex nextVertex;
if (vertices.keySet().contains(componentIDList.get(j))) {
nextVertex = vertices.get(componentIDList.get(j));
}
else {
nextVertex = new Vertex(componentIDList.get(j), compMap.get(componentIDList.get(j)).getNumVars());
vertices.put(componentIDList.get(j), nextVertex);
}
if (nextVertex.componentID != curVertex.componentID) {
HashMap<Integer,Edge> edges = curVertex.getAdjacencies();
// edges != null
Edge e;
if (!edges.keySet().contains(nextVertex.componentID)) {
e = new Edge(nextVertex);
e.addWeight();
edges.put(nextVertex.componentID, e);
}
else {
e = edges.get(nextVertex.componentID);
e.addWeight();
}
}
}
}
}
}
}
}
public void outputDotFile(String fileName) {
try {
BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
out.write("digraph G {\n");
for (Vertex v : vertices.values()) {
String vertexId = v.componentID.toString();
out.write(vertexId + "[shape=\"ellipse\"" + "]\n");
for (Edge e : v.getAdjacencies().values()) {
String targetVertexId = e.target.componentID.toString();
out.write( vertexId + " -> " + targetVertexId + " [label=\"" + e.getWeight() + "\"]\n");
}
}
out.write("}");
out.close();
}
catch (Exception e) {
e.printStackTrace();
System.err.println("Error outputting state graph as dot file.");
}
}
public Vertex selectVerticesToCoalesce() {
VertexComparator comparator = new VertexComparator(maxNumVarsInOneComp);
if (vertices.size() < 1) {
return null;
}
PriorityQueue<Vertex> vertexQueue = new PriorityQueue<Vertex>(vertices.size(),comparator);
for (Vertex vertex : vertices.values()) {
//System.out.println("adding vertex " + vertex.componentID);
vertexQueue.add(vertex);
}
// printVertexQueue(vertexQueue);
Vertex destVertex = vertexQueue.poll(); // vertexToMerge and its most connected neighbor will be coalesced into one component.
if (destVertex.getBestNetGain() < 0)
return null;
return destVertex;
}
@SuppressWarnings("unused")
private static void printVertexQueue(PriorityQueue<Vertex> vertexQueue) {
System.out.println("%%%%%%%%%% vertex queue %%%%%%%%%%%");
int i = 0;
for (Iterator<Vertex> vertexQueueIter = vertexQueue.iterator(); vertexQueueIter.hasNext();) {
Vertex v = vertexQueueIter.next();
System.out.println(i + " (" + v.componentID + " <- " + v.getMostConnectedNeighbor().componentID + ")" + " best net gain: " + v.getBestNetGain());
i++;
}
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
}
}

View file

@ -0,0 +1,271 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn.LpnDecomposition;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Random;
import edu.utah.ece.async.lema.verification.lpn.LPN;
import edu.utah.ece.async.lema.verification.lpn.Place;
import edu.utah.ece.async.lema.verification.lpn.Transition;
import edu.utah.ece.async.lema.verification.lpn.Variable;
import edu.utah.ece.async.lema.verification.platu.main.Options;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class LpnComponentList extends LPN{
private Integer maxNumVarsInOneComp;
private HashMap<Integer, Component> compMap; // <ComponentId, Component>
private HashMap<Variable, ArrayList<Integer>> sharedCompVarsMap;
public LpnComponentList(Integer maxNumProcInOneComp) {
compMap = new HashMap<Integer, Component>();
sharedCompVarsMap = new HashMap<Variable, ArrayList<Integer>>();
this.maxNumVarsInOneComp = maxNumProcInOneComp;
}
public void buildComponents(HashMap<Integer, LpnProcess> processMap, String directory, String lpnFileName) {
HashMap<Variable, ArrayList<LpnProcess>> sharedProcessVarsMap = new HashMap<Variable, ArrayList<LpnProcess>>();
Object[] allProcesses = processMap.values().toArray();
for (int i=0; i<allProcesses.length; i++) {
LpnProcess curProcess = (LpnProcess) allProcesses[i];
for (int j=i+1; j<allProcesses.length; j++) {
LpnProcess nextProcess = (LpnProcess) allProcesses[j];
for (int k=0; k < curProcess.getProcessInput().size(); k++) {
Variable curInput = curProcess.getProcessInput().get(k);
if (nextProcess.getProcessOutput().contains(curInput)) {
if (sharedProcessVarsMap.get(curInput) == null || sharedProcessVarsMap.get(curInput).isEmpty()) {
ArrayList<LpnProcess> procArray = new ArrayList<LpnProcess>(2);
procArray.add(curProcess);
procArray.add(nextProcess);
sharedProcessVarsMap.put(curInput, procArray);
}
else {
if (!sharedProcessVarsMap.get(curInput).contains(curProcess))
sharedProcessVarsMap.get(curInput).add(curProcess);
if (!sharedProcessVarsMap.get(curInput).contains(nextProcess))
sharedProcessVarsMap.get(curInput).add(nextProcess);
}
}
}
for (int k=0; k<curProcess.getProcessOutput().size(); k++) {
Variable curOutput = curProcess.getProcessOutput().get(k);
if (nextProcess.getProcessInput().contains(curOutput)) {
if (sharedProcessVarsMap.get(curOutput) == null || sharedProcessVarsMap.get(curOutput).isEmpty()) {
ArrayList<LpnProcess> procArray = new ArrayList<LpnProcess>(2);
procArray.add(curProcess);
procArray.add(nextProcess);
sharedProcessVarsMap.put(curOutput, procArray);
}
else {
if (!sharedProcessVarsMap.get(curOutput).contains(curProcess))
sharedProcessVarsMap.get(curOutput).add(curProcess);
if (!sharedProcessVarsMap.get(curOutput).contains(nextProcess))
sharedProcessVarsMap.get(curOutput).add(nextProcess);
}
}
}
}
}
if (Options.getDebugMode()) {
printSharedProcessVarMap(sharedProcessVarsMap);
printProcessMap(processMap);
}
// Use wrappers to convert processMap to compMap, and sharedProcessVarsMap to sharedCompMap
for (Integer procID : processMap.keySet()) {
Component comp = new Component(processMap.get(procID));
compMap.put(comp.getComponentId(), comp);
}
for (Variable v : sharedProcessVarsMap.keySet()) {
ArrayList<Integer> compIDList = new ArrayList<Integer>();
for (LpnProcess proc : sharedProcessVarsMap.get(v)) {
compIDList.add(proc.getProcessId());
}
sharedCompVarsMap.put(v, compIDList);
}
boolean quitCoalesing = false;
int iter = 0;
while (!quitCoalesing) {
if (Options.getDebugMode())
printNumProcesses();
LpnComponentGraph componentGraph = new LpnComponentGraph(sharedCompVarsMap, compMap, maxNumVarsInOneComp);
if (Options.getDebugMode()) {
String graphFileName = lpnFileName + maxNumVarsInOneComp + "Vars" + "_compGraph" + iter + ".dot";
componentGraph.outputDotFile(directory + separator + graphFileName);
}
Vertex vertexToCoalesce = componentGraph.selectVerticesToCoalesce();
if (vertexToCoalesce != null) {
Component comp1 = compMap.get(vertexToCoalesce.componentID);
Component comp2 = compMap.get(vertexToCoalesce.getMostConnectedNeighbor().componentID);
if (Options.getDebugMode()) {
System.out.println("*****Coalescing results*******");
System.out.println("vertices to coalesce: " + vertexToCoalesce.componentID + ", " + vertexToCoalesce.getMostConnectedNeighbor().componentID);
System.out.println("best net gain = " + vertexToCoalesce.getBestNetGain());
System.out.println("**********************");
}
coalesceComponents(comp1, comp2);
}
else {
if (Options.getDebugMode())
System.out.println("No net gain of coalescing components.");
quitCoalesing = true;
}
iter++;
}
}
private void printNumProcesses() {
System.out.println("************ processes in each componenet ***********");
for (Component c : compMap.values()) {
System.out.println(c.getComponentId() + " = " + c.getProcessIDList());
}
System.out.println("*****************************************************");
}
private static void printProcessMap(HashMap<Integer, LpnProcess> processMap) {
System.out.println("~~~~~~~~~~~~process map~~~~~~~~~~~~~~");
for (Iterator<Integer> processMapIter = processMap.keySet().iterator(); processMapIter.hasNext();) {
Integer procID = processMapIter.next();
System.out.println("process " + procID + " = " + processMap.get(procID).getProcessId());
}
}
private void printComponentMap() {
System.out.println("~~~~~~~~~~~~component map~~~~~~~~~~~~~~");
for (Iterator<Integer> processMapIter = compMap.keySet().iterator(); processMapIter.hasNext();) {
Integer procID = processMapIter.next();
System.out.println("component " + procID + " = " + compMap.get(procID).getComponentId());
}
}
public void coalesceComponents(Component comp1, Component comp2) {
// coalesce 2 components, each including one process
Component coalescedComp = new Component();
// Create the newly coalesced component's processes, inputs, outputs, internals, and component ID.
coalescedComp.setProcessIDList(comp1.getProcessIDList());
coalescedComp.getProcessIDList().addAll(comp2.getProcessIDList());
Integer coalescedCompId;
do {
Random rand = new Random();
coalescedCompId = rand.nextInt(2000);
} while (compMap.keySet().contains(coalescedCompId));
coalescedComp.setComponentId(coalescedCompId);
ArrayList<Variable> coalescedInternals = coalescedComp.getInternals();
ArrayList<Variable> coalescedOutputs = coalescedComp.getOutputs();
ArrayList<Variable> coalescedInputs = coalescedComp.getInputs();
ArrayList<Variable> sharedVariables = getSharedVariables(comp1, comp2);
ArrayList<Place> coalescedPlaces = coalescedComp.getComponentPlaces();
ArrayList<Transition> coalescedTrans = coalescedComp.getCompTransitions();
comp1.getInputs().removeAll(sharedVariables);
comp2.getInputs().removeAll(sharedVariables);
comp1.getOutputs().removeAll(sharedVariables);
comp2.getOutputs().removeAll(sharedVariables);
coalescedInternals.addAll(sharedVariables);
coalescedInternals.addAll(comp1.getInternals());
coalescedInternals.addAll(comp2.getInternals());
coalescedInputs.addAll(comp1.getInputs());
coalescedInputs.addAll(comp2.getInputs());
coalescedOutputs.addAll(comp1.getOutputs());
coalescedOutputs.addAll(comp2.getOutputs());
coalescedPlaces.addAll(comp1.getComponentPlaces());
coalescedPlaces.addAll(comp2.getComponentPlaces());
coalescedTrans.addAll(comp1.getCompTransitions());
coalescedTrans.addAll(comp2.getCompTransitions());
// Update sharedCompVarsMap
for (Variable sharedVar : sharedCompVarsMap.keySet()) {
if (sharedCompVarsMap.get(sharedVar).contains(comp1.getComponentId())) {
sharedCompVarsMap.get(sharedVar).remove(comp1.getComponentId());
if (!sharedCompVarsMap.get(sharedVar).contains(coalescedComp.getComponentId()))
sharedCompVarsMap.get(sharedVar).add(coalescedComp.getComponentId());
}
if (sharedCompVarsMap.get(sharedVar).contains(comp2.getComponentId())) {
sharedCompVarsMap.get(sharedVar).remove(comp2.getComponentId());
if (!sharedCompVarsMap.get(sharedVar).contains(coalescedComp.getComponentId()))
sharedCompVarsMap.get(sharedVar).add(coalescedComp.getComponentId());
}
}
for (Variable v : sharedVariables) {
sharedCompVarsMap.remove(v);
}
if (Options.getDebugMode())
printSharedCompVarMap();
// Update the compMap: remove the merged components and add the resultant component
compMap.remove(comp1.getComponentId());
compMap.remove(comp2.getComponentId());
compMap.put(coalescedComp.getComponentId(), coalescedComp);
if (Options.getDebugMode())
printComponentMap();
}
private ArrayList<Variable> getSharedVariables(Component comp1,
Component comp2) {
ArrayList<Variable> sharedVars = new ArrayList<Variable>();
for (Variable v : sharedCompVarsMap.keySet()) {
ArrayList<Integer> compIDs = sharedCompVarsMap.get(v);
if (compIDs.contains(comp1.getComponentId()) && compIDs.contains(comp2.getComponentId()))
sharedVars.add(v);
}
return sharedVars;
}
private static void printSharedProcessVarMap(
HashMap<Variable, ArrayList<LpnProcess>> sharedVarMap) {
System.out.println("~~~~~~ shared variables map ~~~~~~~~~~~");
for (Iterator<Variable> sharedVarMapIter = sharedVarMap.keySet().iterator(); sharedVarMapIter.hasNext();) {
Variable curSharedVarMap = sharedVarMapIter.next();
System.out.print(curSharedVarMap + "\t");
ArrayList<LpnProcess> map = sharedVarMap.get(curSharedVarMap);
for (int i=0; i<map.size(); i++) {
System.out.print(map.get(i).getProcessId() + ", ");
}
System.out.print("\n");
}
}
private void printSharedCompVarMap() {
System.out.println("~~~~~~ shared variables map (components)~~~~~~~~~~~");
for (Iterator<Variable> sharedVarMapIter = sharedCompVarsMap.keySet().iterator(); sharedVarMapIter.hasNext();) {
Variable curSharedVarMap = sharedVarMapIter.next();
System.out.print(curSharedVarMap + "\t");
ArrayList<Integer> map = sharedCompVarsMap.get(curSharedVarMap);
for (int i=0; i<map.size(); i++) {
System.out.print(map.get(i) + ", ");
}
System.out.print("\n");
}
}
public Component getComponent(Integer componentID) {
return compMap.get(componentID);
}
public HashMap<Integer, Component> getComponentMap() {
return compMap;
}
public HashMap<Variable,ArrayList<Integer>> getSharedCompVarsMap() {
return sharedCompVarsMap;
}
}

View file

@ -0,0 +1,382 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn.LpnDecomposition;
import java.util.ArrayList;
import java.util.Iterator;
import edu.utah.ece.async.lema.verification.lpn.LPN;
import edu.utah.ece.async.lema.verification.lpn.Place;
import edu.utah.ece.async.lema.verification.lpn.Transition;
import edu.utah.ece.async.lema.verification.lpn.Variable;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class LpnProcess extends LPN {
private ArrayList<Transition> processTrans = new ArrayList<Transition>();
private ArrayList<Place> processPlaces = new ArrayList<Place>();
private ArrayList<Variable> processInput = new ArrayList<Variable>();
private ArrayList<Variable> processOutput = new ArrayList<Variable>();
private ArrayList<Variable> processInternal = new ArrayList<Variable>();
private int id;
private boolean isStateMachine;
public LpnProcess(Integer procId) {
id = procId;
isStateMachine = true;
}
public int getProcessId() {
return id;
}
public void addTranToProcess(Transition curTran) {
processTrans.add(curTran);
}
public void addPlaceToProcess(Place curPlace) {
processPlaces.add(curPlace);
}
// /**
// * This method assigns at least one sticky transition to each process. Transitions whose preset places are marked are considered to be sticky
// * for each process. The purpose of assigning sticky transitions is to break all cycles in each process. In general, one sticky transition is
// * sufficient to break the cycle. However, Floyd's all-pairs shortest-path algorithm (binary) is used to find additional transition(s) that can
// * help to cut the cycle(s).
// */
// @SuppressWarnings("unchecked")
// public void assignStickyTransitions() {
// // Assign transition(s) with marked post to be sticky
// for (Place p : processPlaces) {
// if (p.isMarked()) {
// if (p.getPreset() != null && p.getPreset().length > 0) {
// Transition[] transitions = p.getPreset();
// for (int i=0; i<transitions.length; i++) {
// transitions[i].setSticky(true);
// }
// }
// else {
// Integer selectedTran;
// do {
// Random rand = new Random();
// selectedTran = rand.nextInt(processTrans.size());
// }
// while (processTrans.get(selectedTran).getName().contains("_dummy"));
// processTrans.get(selectedTran).setSticky(true);
// }
// }
// }
// ArrayList<Transition> processTransCopy = (ArrayList<Transition>) processTrans.clone();
// ArrayList<Transition> transToRemove = new ArrayList<Transition>();
// DualHashMap<Transition, Integer> tranIndexInMatrixMap = new DualHashMap<Transition, Integer>();
// int index = -1;
// for (Iterator<Transition> processTransCopyIter = processTransCopy.iterator(); processTransCopyIter.hasNext();) {
// Transition curTran = processTransCopyIter.next();
// if (curTran.isSticky() || curTran.getName().contains("_dummy")) {
// transToRemove.add(curTran);
// continue;
// }
// index++;
// tranIndexInMatrixMap.put(curTran, index);
// }
// processTransCopy.removeAll(transToRemove);
// // Floyd's all-pairs shortest path
// ArrayList<ArrayList<Boolean>> matrix = new ArrayList<ArrayList<Boolean>>();
// Integer numCycles = 0;
// do {
// if (processTransCopy.size() == 0) {
// continue;
// }
// ArrayList<Boolean> row = new ArrayList<Boolean>();
// for (int i=0; i<processTransCopy.size(); i++) {
// for (int j=0; j<processTransCopy.size(); j++) {
// row.add(j, false);
// }
// matrix.add(i, (ArrayList<Boolean>) row.clone());
// row.clear();
// }
// // find the next reachable transition(s) from the current transition
// for (int i=0; i<processTransCopy.size(); i++) {
// Transition curTran = processTransCopy.get(i);
// for (Place p : curTran.getPostset()) {
// for (Transition tran : p.getPostset()) {
// if (processTransCopy.contains(tran)) {
// Integer tranIndexInMatrix = tranIndexInMatrixMap.get(tran);
// Integer curTranIndexInMatrix = tranIndexInMatrixMap.get(curTran);
// matrix.get(curTranIndexInMatrix).set(tranIndexInMatrix, true);
// }
// }
// }
// }
// // update reachability
// for (int k=0; k<processTransCopy.size(); k++) {
// for (int i=0; i<processTransCopy.size(); i++) {
// for (int j=0; j<processTransCopy.size(); j++) {
// if (matrix.get(i).get(k) && matrix.get(k).get(j)) {
// matrix.get(i).set(j, true);
// }
// }
// }
// }
// // Check to see if there is still any cycles left. If a transition can reach itself, then there is a loop.
// Transition tranWithBiggestPreset = new Transition();
// for (int i=0; i<matrix.size(); i++) {
// if (matrix.get(i).get(i)) {
// numCycles ++;
// if (tranIndexInMatrixMap.getKey(i).getPreset().length > tranWithBiggestPreset.getPreset().length) {
// tranWithBiggestPreset = tranIndexInMatrixMap.getKey(i);
// }
// }
// }
// tranWithBiggestPreset.setSticky(true);
// // Remove the sticky transition in the matrix.
// Integer tranWithBiggestPresetIndex = tranIndexInMatrixMap.getValue(tranWithBiggestPreset);
// processTransCopy.remove(tranWithBiggestPreset);
// for (int i=0; i<matrix.size(); i++) {
// matrix.get(i).remove(tranWithBiggestPresetIndex);
// }
// matrix.remove(tranWithBiggestPresetIndex);
// numCycles --;
// }
// while (numCycles > 0 && processTransCopy.size() > 0);
// }
// public void printProcWithStickyTrans() {
// System.out.println("*******Sticky Transitions*******");
// System.out.println("Process ID:" + this.getProcessId());
// for (int i=0; i < this.processTrans.size(); i++) {
// if (processTrans.get(i).isSticky()) {
// System.out.println(processTrans.get(i).getName() + " " + processTrans.get(i).getIndex());
// }
// }
// System.out.println("********************");
// }
// /**
// * This method assigns at least one sticky transition to each process. Transitions whose preset places are marked are considered to be sticky
// * for each process. The purpose of assigning sticky transitions is to break all cycles in each process. In general, one sticky transition is
// * sufficient to break the cycle. However, Floyd<EFBFBD>s all-pairs shortest-path algorithm (binary) is used to find additional transition(s) that can
// * help to cut the cycle(s).
// */
// @SuppressWarnings("unchecked")
// public void assignStickyTransitions() {
// // Assign transition(s) with marked post to be sticky
// for (Place p : processPlaces) {
// if (p.isMarked()) {
// if (p.getPreset() != null && p.getPreset().length > 0) {
// Transition[] transitions = p.getPreset();
// for (int i=0; i<transitions.length; i++) {
// transitions[i].setSticky(true);
// }
// }
// else {
// Integer selectedTran;
// do {
// Random rand = new Random();
// selectedTran = rand.nextInt(processTrans.size());
// }
// while (processTrans.get(selectedTran).getName().contains("_dummy"));
// processTrans.get(selectedTran).setSticky(true);
// }
// }
// }
// ArrayList<Transition> processTransCopy = (ArrayList<Transition>) processTrans.clone();
// ArrayList<Transition> transToRemove = new ArrayList<Transition>();
// DualHashMap<Transition, Integer> tranIndexInMatrixMap = new DualHashMap<Transition, Integer>();
// int index = -1;
// for (Iterator<Transition> processTransCopyIter = processTransCopy.iterator(); processTransCopyIter.hasNext();) {
// Transition curTran = processTransCopyIter.next();
// if (curTran.isSticky() || curTran.getName().contains("_dummy")) {
// transToRemove.add(curTran);
// continue;
// }
// index++;
// tranIndexInMatrixMap.put(curTran, index);
// }
// processTransCopy.removeAll(transToRemove);
// // Floyd's all-pairs shortest path
// ArrayList<ArrayList<Boolean>> matrix = new ArrayList<ArrayList<Boolean>>();
// Integer numCycles = 0;
// do {
// if (processTransCopy.size() == 0) {
// continue;
// }
// ArrayList<Boolean> row = new ArrayList<Boolean>();
// for (int i=0; i<processTransCopy.size(); i++) {
// for (int j=0; j<processTransCopy.size(); j++) {
// row.add(j, false);
// }
// matrix.add(i, (ArrayList<Boolean>) row.clone());
// row.clear();
// }
// // find the next reachable transition(s) from the current transition
// for (int i=0; i<processTransCopy.size(); i++) {
// Transition curTran = processTransCopy.get(i);
// for (Place p : curTran.getPostset()) {
// for (Transition tran : p.getPostset()) {
// if (processTransCopy.contains(tran)) {
// Integer tranIndexInMatrix = tranIndexInMatrixMap.get(tran);
// Integer curTranIndexInMatrix = tranIndexInMatrixMap.get(curTran);
// matrix.get(curTranIndexInMatrix).set(tranIndexInMatrix, true);
// }
// }
// }
// }
// // update reachability
// for (int k=0; k<processTransCopy.size(); k++) {
// for (int i=0; i<processTransCopy.size(); i++) {
// for (int j=0; j<processTransCopy.size(); j++) {
// if (matrix.get(i).get(k) && matrix.get(k).get(j)) {
// matrix.get(i).set(j, true);
// }
// }
// }
// }
// // Check to see if there is still any cycles left. If a transition can reach itself, then there is a loop.
// Transition tranWithBiggestPreset = new Transition();
// for (int i=0; i<matrix.size(); i++) {
// if (matrix.get(i).get(i)) {
// numCycles ++;
// if (tranIndexInMatrixMap.getKey(i).getPreset().length > tranWithBiggestPreset.getPreset().length) {
// tranWithBiggestPreset = tranIndexInMatrixMap.getKey(i);
// }
// }
// }
// tranWithBiggestPreset.setSticky(true);
// // Remove the sticky transition in the matrix.
// Integer tranWithBiggestPresetIndex = tranIndexInMatrixMap.getValue(tranWithBiggestPreset);
// processTransCopy.remove(tranWithBiggestPreset);
// for (int i=0; i<matrix.size(); i++) {
// matrix.get(i).remove(tranWithBiggestPresetIndex);
// }
// matrix.remove(tranWithBiggestPresetIndex);
// numCycles --;
// }
// while (numCycles > 0 && processTransCopy.size() > 0);
// }
public void print() {
System.out.print("Process ID: " + this.getProcessId() + "\n");
ArrayList<Transition> trans = this.getProcessTransitions();
System.out.println("Transitions:");
for (Iterator<Transition> transIter = trans.iterator(); transIter.hasNext();) {
System.out.print(transIter.next() + " ");
}
System.out.print("\n");
System.out.println("Places:");
ArrayList<Place> places = this.getProcessPlaces();
for (Iterator<Place> placesIter = places.iterator(); placesIter.hasNext();) {
System.out.print(placesIter.next() + " ");
}
System.out.print("\n");
System.out.println("Inputs:");
ArrayList<Variable> input = this.getProcessInput();
for (Iterator<Variable> inputIter = input.iterator(); inputIter.hasNext();) {
System.out.println(inputIter.next() + " ");
}
System.out.print("\n");
System.out.println("Outputs:");
ArrayList<Variable> output = this.getProcessOutput();
for (Iterator<Variable> outputIter = output.iterator(); outputIter.hasNext();) {
System.out.println(outputIter.next() + " ");
}
System.out.print("\n");
System.out.println("Internals:");
ArrayList<Variable> internal = this.getProcessInternal();
for (Iterator<Variable> internalIter = internal.iterator(); internalIter.hasNext();) {
System.out.println(internalIter.next() + " ");
}
System.out.print("\n");
System.out.println("----------------------------");
}
public ArrayList<Place> getProcessPlaces() {
return processPlaces;
}
public ArrayList<Transition> getProcessTransitions() {
return processTrans;
}
public ArrayList<Variable> getProcessInput() {
return processInput;
}
public ArrayList<Variable> getProcessOutput() {
return processOutput;
}
public ArrayList<Variable> getProcessInternal() {
return processInternal;
}
public ArrayList<Variable> getProcessVariables() {
ArrayList<Variable> variables = new ArrayList<Variable>();
variables.addAll(processInput);
variables.addAll(processOutput);
variables.addAll(processInternal);
return variables;
}
public int getProcessVarSize() {
return processInternal.size() + processInput.size() + processOutput.size();
}
public LPN buildLPN(LPN lpnProc) {
// Places
for (int i=0; i< this.getProcessPlaces().size(); i++) {
Place p = this.getProcessPlaces().get(i);
lpnProc.addPlace(p.getName(), p.isMarked());
}
// Transitions
for (int i=0; i< this.getProcessTransitions().size(); i++) {
Transition t = this.getProcessTransitions().get(i);
t.setIndex(i);
lpnProc.addTransition(t);
}
// Inputs
for (int i=0; i< this.getProcessInput().size(); i++) {
Variable var = this.getProcessInput().get(i);
lpnProc.addInput(var.getName(), var.getType(), var.getInitValue());
}
// Outputs
for (int i=0; i< this.getProcessOutput().size(); i++) {
Variable var = this.getProcessOutput().get(i);
lpnProc.addOutput(var.getName(), var.getType(), var.getInitValue());
}
// Internal
for (int i=0; i< this.getProcessInternal().size(); i++) {
Variable var = this.getProcessInternal().get(i);
lpnProc.addInternal(var.getName(), var.getType(), var.getInitValue());
}
return lpnProc;
}
public void setStateMachineFlag(boolean isSM) {
isStateMachine = isSM;
}
public boolean getStateMachineFlag() {
return isStateMachine;
}
}

View file

@ -0,0 +1,105 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn.LpnDecomposition;
import java.util.HashMap;
import edu.utah.ece.async.lema.verification.platu.main.Options;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Vertex {
public final Integer componentID;
private HashMap<Integer, Edge> adjacencies;
private Edge edgeToMostConnectedNeighbor;
private int numVariables;
private int bestNetGain;
public Vertex(Integer componentID, int numVariables) {
this.componentID = componentID;
this.numVariables = numVariables;
adjacencies = new HashMap<Integer, Edge>();
bestNetGain = MinusINF;
}
public HashMap<Integer, Edge> getAdjacencies() {
return this.adjacencies;
}
/**
* This method calculates the best net gain when coalesce this vertex with one of its neighbor vertices.
* The net gain is calculated as follows: net gain = (# internal variables created after coalescing) - (# remaining global variables
* of the target process after coalescing). The term "internal" and "global" are defined here with respect to the coalesced component.
* @param maxNumVarsInOneComp
* @return
*/
public int calculateBestNetGain(int maxNumVarsInOneComp) {
for (Integer i : adjacencies.keySet()){
Edge e = adjacencies.get(i);
Vertex targetVertex = e.target;
int numInternal = e.getWeight(); // e is the shared edge between this vertex and the target vertex.
if ((this.getNumVars() + targetVertex.getNumVars() - numInternal) > maxNumVarsInOneComp) {
bestNetGain = MinusINF;
if (Options.getDebugMode()) {
System.out.println("^^^^^^^^^^^^^^^^^^^^^^^");
System.out.println("Component " + this.componentID + " has " + this.getNumVars() + " variable(s).");
System.out.println("Component " + targetVertex.componentID + " has " + targetVertex.getNumVars() + " variable(s).");
System.out.println("(" + this.componentID + " <- "
+ targetVertex.componentID + ")" + " bestNetGain = " + bestNetGain);
System.out.println("vvvvvvvvvvvvvvvvvvvvvvv");
}
}
else {
int numRemainGlobal = targetVertex.getAllEdgesWeights() - numInternal;
if (bestNetGain < numInternal - numRemainGlobal) {
bestNetGain = numInternal - numRemainGlobal;
edgeToMostConnectedNeighbor = e;
}
if (Options.getDebugMode())
System.out.println("(" + this.componentID + " <- "
+ targetVertex.componentID + ")" + " bestNetGain = " + bestNetGain);
}
}
return bestNetGain;
}
private int getNumVars() {
return numVariables;
}
public int getBestNetGain() {
return bestNetGain;
}
private int getAllEdgesWeights() {
int allEdgesWeights = 0;
for (Edge e : adjacencies.values()) {
allEdgesWeights = allEdgesWeights + e.getWeight();
}
return allEdgesWeights;
}
public static int MinusINF = -2147483648;
public Vertex getMostConnectedNeighbor() {
return edgeToMostConnectedNeighbor.target;
}
}

View file

@ -0,0 +1,41 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn.LpnDecomposition;
import java.util.Comparator;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class VertexComparator implements Comparator<Vertex>{
private int maxNumVarsInOneComp;
public VertexComparator(Integer maxNumVarsInOneComp) {
this.maxNumVarsInOneComp = maxNumVarsInOneComp;
}
@Override
public int compare(Vertex v1, Vertex v2) {
if (v1.calculateBestNetGain(maxNumVarsInOneComp) >= v2.calculateBestNetGain(maxNumVarsInOneComp))
return -1;
return 1;
// else
// return 0;
}
}

View file

@ -0,0 +1,205 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */
/* JavaCCOptions:KEEP_LINE_COL=null */
package edu.utah.ece.async.lema.verification.lpn;
/**
* This exception is thrown when parse errors are encountered.
* You can explicitly create objects of this exception type by
* calling the method generateParseException in the generated
* parser.
*
* You can modify this class to customize your error reporting
* mechanisms so long as you retain the public fields.
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class ParseException extends Exception {
/**
* The version identifier for this Serializable class.
* Increment only if the <i>serialized</i> form of the
* class changes.
*/
private static final long serialVersionUID = 1L;
/**
* This constructor is used by the method "generateParseException"
* in the generated parser. Calling this constructor generates
* a new object of this type with the fields "currentToken",
* "expectedTokenSequences", and "tokenImage" set.
*/
public ParseException(Token currentTokenVal,
int[][] expectedTokenSequencesVal,
String[] tokenImageVal
)
{
super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal));
currentToken = currentTokenVal;
expectedTokenSequences = expectedTokenSequencesVal;
tokenImage = tokenImageVal;
}
/**
* The following constructors are for use by you for whatever
* purpose you can think of. Constructing the exception in this
* manner makes the exception behave in the normal way - i.e., as
* documented in the class "Throwable". The fields "errorToken",
* "expectedTokenSequences", and "tokenImage" do not contain
* relevant information. The JavaCC generated code does not use
* these constructors.
*/
public ParseException() {
super();
}
/** Constructor with message. */
public ParseException(String message) {
super(message);
}
/**
* This is the last token that has been consumed successfully. If
* this object has been created due to a parse error, the token
* followng this token will (therefore) be the first error token.
*/
public Token currentToken;
/**
* Each entry in this array is an array of integers. Each array
* of integers represents a sequence of tokens (by their ordinal
* values) that is expected at this point of the parse.
*/
public int[][] expectedTokenSequences;
/**
* This is a reference to the "tokenImage" array of the generated
* parser within which the parse error occurred. This array is
* defined in the generated ...Constants interface.
*/
public String[] tokenImage;
/**
* It uses "currentToken" and "expectedTokenSequences" to generate a parse
* error message and returns it. If this object has been created
* due to a parse error, and you do not catch it (it gets thrown
* from the parser) the correct error message
* gets displayed.
*/
private static String initialise(Token currentToken,
int[][] expectedTokenSequences,
String[] tokenImage) {
String eol = System.getProperty("line.separator", "\n");
StringBuffer expected = new StringBuffer();
int maxSize = 0;
for (int i = 0; i < expectedTokenSequences.length; i++) {
if (maxSize < expectedTokenSequences[i].length) {
maxSize = expectedTokenSequences[i].length;
}
for (int j = 0; j < expectedTokenSequences[i].length; j++) {
expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
}
if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) {
expected.append("...");
}
expected.append(eol).append(" ");
}
String retval = "Encountered \"";
Token tok = currentToken.next;
for (int i = 0; i < maxSize; i++) {
if (i != 0) retval += " ";
if (tok.kind == 0) {
retval += tokenImage[0];
break;
}
retval += " " + tokenImage[tok.kind];
retval += " \"";
retval += add_escapes(tok.image);
retval += " \"";
tok = tok.next;
}
retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
retval += "." + eol;
if (expectedTokenSequences.length == 1) {
retval += "Was expecting:" + eol + " ";
} else {
retval += "Was expecting one of:" + eol + " ";
}
retval += expected.toString();
return retval;
}
/**
* The end of line string for this machine.
*/
protected String eol = System.getProperty("line.separator", "\n");
/**
* Used to convert raw characters to their escaped version
* when these raw version cannot be used as part of an ASCII
* string literal.
*/
static String add_escapes(String str) {
StringBuffer retval = new StringBuffer();
char ch;
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i))
{
case 0 :
continue;
case '\b':
retval.append("\\b");
continue;
case '\t':
retval.append("\\t");
continue;
case '\n':
retval.append("\\n");
continue;
case '\f':
retval.append("\\f");
continue;
case '\r':
retval.append("\\r");
continue;
case '\"':
retval.append("\\\"");
continue;
case '\'':
retval.append("\\\'");
continue;
case '\\':
retval.append("\\\\");
continue;
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
String s = "0000" + Integer.toString(ch, 16);
retval.append("\\u" + s.substring(s.length() - 4, s.length()));
} else {
retval.append(ch);
}
continue;
}
}
return retval.toString();
}
}
/* JavaCC - OriginalChecksum=3de8a380650a6d52449760a316ba5b6e (do not edit this line) */

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,449 @@
options {
JAVA_UNICODE_ESCAPE = true;
STATIC = false;
}
PARSER_BEGIN(Parser)
package lpn.parser;
public class Parser {
public Parser (String property) {
this(new java.io.ByteArrayInputStream(property.getBytes()));
}
public boolean parseProperty() {
try {
Goal();
return true;
}
catch (Exception e) {
System.out.println(e.toString());
return false;
}
}
public static void main(String [] args) {
try {
Parser p = new Parser(System.in);
//Parser p = new Parser(args[0]);
p.Goal();
}
catch (Exception e) {
System.out.println(e.toString());
}
}
}
PARSER_END(Parser)
TOKEN : {
<DOT: "."> |
<ATACS: ([" ", "\t"])*"#@" > |
<END: (<DOT>"end"|<DOT>"END")> |
<INPUTS: (<DOT>"inputs"|<DOT>"INPUTS")> |
<INIT_STATE: <DOT>"init_state"> |
<DUMMYS: (<DOT>"dummy"|<DOT>"DUMMY")> |
<FAILTRANS: (<DOT>"failtrans"|<DOT>"FAILTRANS")> |
<VARIABLES: (<DOT>"variables"|<DOT>"VARIABLES")> |
<INTEGERS: (<DOT>"integers"|<DOT>"INTEGERS")> |
<NONINPS: (<DOT>"noninp"|<DOT>"NONINP")> |
<KEEPS: (<DOT>"keep"|<DOT>"KEEP")> |
<ABSTRACTS: (<DOT>"abstract"|<DOT>"ABSTRACT")> |
<CONTINUOUS: (<DOT>"continuous"|<DOT>"CONTINUOUS")> |
<RATES: (<DOT>"rates"|<DOT>"RATES")> |
<INITRATES: (<DOT>"init_rates"|<DOT>"INIT_RATES")> |
<INITVALS: (<DOT>"init_vals"|<DOT>"INIT_VALS")> |
<INITINTS: (<DOT>"init_ints"|<DOT>"INIT_INTS")> |
<INVARIANTS:(<DOT>"invariants"|<DOT>"INVARIANTS")> |
<ENABLINGS: (<DOT>"enablings"|<DOT>"ENABLINGS")> |
<ASSIGNS: (<DOT>"assignments"|<DOT>"ASSIGNMENTS")> |
<TRANS_RATES: (<DOT>"transition_rates"|<DOT>"TRANSITION_RATES")> |
<RATE_ASSIGNS: (<DOT>"rate_assignments"|<DOT>"RATE_ASSIGNMENTS")> |
<INT_ASSIGNS: (<DOT>"int_assignments"|<DOT>"INT_ASSIGNMENTS")> |
<DELAY_ASSIGNS: (<DOT>"delay_assignments"|<DOT>"DELAY_ASSIGNMENTS")> |
<PRIORITY_ASSIGNS: (<DOT>"priority_assignments"|<DOT>"PRIORITY_ASSIGNMENTS")> |
<BOOL_ASSIGNS: (<DOT>"boolean_assignments"|<DOT>"BOOLEAN_ASSIGNMENTS")> |
<OUTPUTS: (<DOT>"outputs"|<DOT>"OUTPUTS")> |
<INTERNAL: (<DOT>"internal"|<DOT>"INTERNAL")> |
<GRAPH: (<DOT>"graph"|<DOT>"GRAPH")> |
<PROPERTY: (<DOT>"property"|<DOT>"PROPERTY")> |
<MARKING: (<DOT>"marking"|<DOT>"MARKING)")>|
<NAME: (<DOT>"name"|<DOT>"NAME")> |
<MINF: "min"> |
<MAXF: "max"> |
<IDIV: "idiv"> |
<FLOOR: "floor"> |
<CEIL: "ceil"> |
<UNIFORM: "uniform"> |
<NORMAL: "normal"> |
<EXPONENTIAL: "exponential"> |
<GAMMA: "gamma"> |
<LOGNORMAL: "lognormal"> |
<CHISQ: "chisq"> |
<LAPLACE: "laplace"> |
<CAUCHY: "cauchy"> |
<RAYLEIGH: "rayleigh"> |
<POISSON: "poisson"> |
<BINOMIAL: "binomial"> |
<BERNOULLI: "bernoulli"> |
<BITNOT: "NOT"> |
<BITOR: "OR"> |
<BITAND: "AND"> |
<BITXOR: "XOR"> |
<INT: "INT"> |
<BOOL: "BOOL"> |
<BIT: "BIT"> |
<RATE: "rate"> |
<VERIFY: "verify"> |
<SEARCH: "search"> |
<ASSIGN: ":="> |
<IMPLIC: "=>"> |
<COMMA: ","> |
<QMARK: "?"> |
<EQUAL: "="> |
<OBRACE: "{"> |
<LESSTHAN: "<"> |
<BOOL_FALSE: "false"> |
<BOOL_TRUE: "true"> |
<AU: "AU"> |
<EU: "EU"> |
<EG: "EG"> |
<EF: "EF"> |
<AG: "AG"> |
<AF: "AF"> |
<PG: "PG"> |
<PF: "PF"> |
<PU: "PU"> |
<PX: "PX"> |
<Pr: "Pr"> |
<Ss: "St"> |
<OSQUARE: "["> |
<CSQUARE: "]"> |
<GREATERTHAN: ">"> |
<CBRACE: "}"> |
<DISABLE: ")d"> |
<INF: "inf"> |
<SYMBOL: ["!","?"]> |
<ID: (<LETTER>|<SYMBOL>)(<LETTER>|<DIGIT>|<SYMBOL>|<DOT>)*> |
<NUM: (<DIGIT>)+(<DOT>(<DIGIT>)+)?("E")("+"|"-")?(<DIGIT>)+> |
<INTEGER: (<DIGIT>)+> |
<REAL: <INTEGER><DOT><INTEGER>|<INTEGER>"e"<INTEGER>|<INTEGER>"e-"<INTEGER>|<INTEGER>"E"<INTEGER>|<INTEGER>"E-"<INTEGER>|<INTEGER><DOT><INTEGER>"e"<INTEGER>|<INTEGER><DOT><INTEGER>"e-"<INTEGER>|<INTEGER><DOT><INTEGER>"E"<INTEGER>|<INTEGER><DOT><INTEGER>"E-"<INTEGER>|<INTEGER><DOT><INTEGER>"e+"<INTEGER>|<INTEGER><DOT><INTEGER>"E+"<INTEGER>> |
<#LETTER: ["a"-"z"]|["A"-"Z"]|["_"]> |
<#DIGIT: ["0"-"9"]> |
<PLUS: "+"> |
<MINUS: "-"> |
<OPAR: "("> |
<CPAR: ")"> |
<MULT: "*"> |
<MOD: "%"> |
<POWER: "^"> |
<NOT: "~"> |
<DIV:"/"> |
<AND: "&"> |
<OR: "|"> |
<GEQ: ">="> |
<LEQ: "<="> |
<SEMICOLON: ";"> |
<UNKNOWN: "\\" >
}
SKIP : { " " | "\t" | "\n" | "\r" | "\r\n" | <COMMENTS:(<DELIM>)*"#"(~["@","\n"])*> | <#DELIM: ([" ", "\t"])+>}
void Goal() :
{}
{
(Property())* <EOF>
}
void Property():
{}
{
Props()
| Probproperty()
}
void Probproperty():
{}
{
LOOKAHEAD(3)<Pr> Relop() <REAL> <OBRACE> Probprop() <CBRACE>
| LOOKAHEAD(2)<Pr> <OBRACE> Probprop() <CBRACE>
| LOOKAHEAD(2)<Pr> <EQUAL> <QMARK> <OBRACE> Probprop() <CBRACE>
| LOOKAHEAD(3)<Ss> Relop() <REAL> <OBRACE> Probproperty() <CBRACE>
| LOOKAHEAD(2)<Ss> <OBRACE> Probproperty() <CBRACE>
| LOOKAHEAD(2)<Ss> <EQUAL> <QMARK> <OBRACE> Probproperty() <CBRACE>
| Hsf()
}
void Probprop():
{}
{
<PG> Bound() <OPAR> Probproperty() <CPAR>
| <PF> Bound() <OPAR> Probproperty() <CPAR>
| Probproperty() <PU> Bound() Probproperty()
}
//void Props():
//{}
//{
// LOOKAHEAD(3) Prop() Andprop()
// | LOOKAHEAD(3) Prop() Orprop()
// | LOOKAHEAD(3) Prop() Impliesprop()
// | Prop()
//}
void Props():
{}
{
Prop() Props_prime()
}
void Props_prime():
{}
{
Andprop()
| Orprop()
| Impliesprop()
}
void Andprop():
{}
{
<AND> Prop() Andprop()
| {}
}
void Orprop():
{}
{
<OR> Prop() Orprop()
| {}
}
void Impliesprop():
{}
{
<MINUS> <GREATERTHAN> Prop() Impliesprop()
| {}
}
//void Prop():
//{}
//{
// LOOKAHEAD(3) Fronttype() <OPAR> Bound() Hsf() <CPAR>
// | Fronttype() <OPAR> Bound() Prop()<CPAR>
// | Midprop()
//}
void Prop():
{}
{
Fronttype() Bound() <OPAR> Prop_prime() <CPAR>
| Midprop()
}
void Prop_prime():
{}
{
Hsf()
| Fronttype() Bound() <OPAR> Prop_prime() <CPAR>
| Midprop()
}
// void Midprop():
//{}
//{
// <OPAR> Propinner() <CPAR>
//}
void Midprop():
{}
{
<OBRACE> Propinner() <CBRACE>
}
//void Propinner():
//{}
//{
// LOOKAHEAD(3) Prop() Midtype() Bound() Prop()
// | LOOKAHEAD(3) Prop() Midtype() Bound() Hsf()
// | LOOKAHEAD(3) Hsf() Midtype() Bound() Prop()
// | Hsf() Midtype() Bound() Hsf()
//}
void Propinner():
{}
{
Hsf() Midtype() Bound() Propinner_prime()
| Prop() Midtype() Bound() Propinner_prime()
}
void Propinner_prime():
{}
{
Prop()
| Hsf()
}
void Fronttype():
{}
{
<AG> | <AF> | <EG> | <EF>
}
void Midtype():
{}
{
<AU> | <EU>
}
void Bound():
{}
{
LOOKAHEAD(2)<OSQUARE> Relop() Hsf() <CSQUARE>
| <OSQUARE> Hsf() <COMMA> Hsf() <CSQUARE>
| {}
}
void Hsf():
{}
{
Andexpr() Hsf_prime()
}
void Hsf_prime():
{}
{
<OR> Andexpr() Hsf_prime()
| <IMPLIC> Andexpr() Hsf_prime()
| {}
}
void Andexpr():
{}
{
Relation() Andexpr_prime()
}
void Andexpr_prime():
{}
{
<AND> Relation() Andexpr_prime()
| {}
}
void Relation():
{}
{
Arithexpr() Relation_prime()
| <NOT> Relation()
| <BIT> <OPAR> Arithexpr() <COMMA> Arithexpr() <CPAR>
}
void Relation_prime():
{}
{
Relop() Arithexpr()
| {}
}
void Arithexpr():
{}
{
Multexpr() Arithexpr_prime()
}
void Arithexpr_prime():
{}
{
<PLUS> Multexpr() Arithexpr_prime()
| <MINUS> Multexpr() Arithexpr_prime()
| {}
}
void Multexpr():
{}
{
Term() Multexpr_prime()
}
void Multexpr_prime():
{}
{
<MULT> Term() Multexpr_prime()
| <DIV> Term() Multexpr_prime()
| <MOD> Term() Multexpr_prime()
| <POWER> Term() Multexpr_prime()
| Id()
| {}
}
void Term():
{}
{
<OPAR> Hsf() <CPAR>
| Id()
| <INTEGER>
| <REAL>
| <INF>
| <RATE> <OPAR> Id() <CPAR>
| <INT> <OPAR> Hsf() <CPAR>
| <MINUS> Term()
| <BOOL_FALSE>
| <BOOL_TRUE>
| Unop() <OPAR> Arithexpr() <CPAR>
| Binop() <OPAR> Arithexpr() <COMMA> Arithexpr() <CPAR>
}
void Relop():
{}
{
<EQUAL>
| LOOKAHEAD(2) <LESSTHAN>
| <LEQ>
| LOOKAHEAD(2) <GREATERTHAN>
| <GEQ>
}
void Unop():
{}
{
<BITNOT>
| <EXPONENTIAL>
| <CHISQ>
| <LAPLACE>
| <CAUCHY>
| <RAYLEIGH>
| <POISSON>
| <BERNOULLI>
| <BOOL>
| <FLOOR>
| <CEIL>
}
void Binop():
{}
{
<BITOR>
| <BITAND>
| <BITXOR>
| <UNIFORM>
| <NORMAL>
| <GAMMA>
| <LOGNORMAL>
| <BINOMIAL>
| <MINF>
| <MAXF>
| <IDIV>
}
void Id():
{}
{
<ID>
}

View file

@ -0,0 +1,375 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
/* Generated By:JavaCC: Do not edit this line. ParserConstants.java */
package edu.utah.ece.async.lema.verification.lpn;
/**
* Token literal values and constants.
* Generated by org.javacc.parser.OtherFilesGen#start()
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public interface ParserConstants {
/** End of File. */
int EOF = 0;
/** RegularExpression Id. */
int DOT = 1;
/** RegularExpression Id. */
int ATACS = 2;
/** RegularExpression Id. */
int END = 3;
/** RegularExpression Id. */
int INPUTS = 4;
/** RegularExpression Id. */
int INIT_STATE = 5;
/** RegularExpression Id. */
int DUMMYS = 6;
/** RegularExpression Id. */
int FAILTRANS = 7;
/** RegularExpression Id. */
int VARIABLES = 8;
/** RegularExpression Id. */
int INTEGERS = 9;
/** RegularExpression Id. */
int NONINPS = 10;
/** RegularExpression Id. */
int KEEPS = 11;
/** RegularExpression Id. */
int ABSTRACTS = 12;
/** RegularExpression Id. */
int CONTINUOUS = 13;
/** RegularExpression Id. */
int RATES = 14;
/** RegularExpression Id. */
int INITRATES = 15;
/** RegularExpression Id. */
int INITVALS = 16;
/** RegularExpression Id. */
int INITINTS = 17;
/** RegularExpression Id. */
int INVARIANTS = 18;
/** RegularExpression Id. */
int ENABLINGS = 19;
/** RegularExpression Id. */
int ASSIGNS = 20;
/** RegularExpression Id. */
int TRANS_RATES = 21;
/** RegularExpression Id. */
int RATE_ASSIGNS = 22;
/** RegularExpression Id. */
int INT_ASSIGNS = 23;
/** RegularExpression Id. */
int DELAY_ASSIGNS = 24;
/** RegularExpression Id. */
int PRIORITY_ASSIGNS = 25;
/** RegularExpression Id. */
int BOOL_ASSIGNS = 26;
/** RegularExpression Id. */
int OUTPUTS = 27;
/** RegularExpression Id. */
int INTERNAL = 28;
/** RegularExpression Id. */
int GRAPH = 29;
/** RegularExpression Id. */
int PROPERTY = 30;
/** RegularExpression Id. */
int MARKING = 31;
/** RegularExpression Id. */
int NAME = 32;
/** RegularExpression Id. */
int MINF = 33;
/** RegularExpression Id. */
int MAXF = 34;
/** RegularExpression Id. */
int IDIV = 35;
/** RegularExpression Id. */
int FLOOR = 36;
/** RegularExpression Id. */
int CEIL = 37;
/** RegularExpression Id. */
int UNIFORM = 38;
/** RegularExpression Id. */
int NORMAL = 39;
/** RegularExpression Id. */
int EXPONENTIAL = 40;
/** RegularExpression Id. */
int GAMMA = 41;
/** RegularExpression Id. */
int LOGNORMAL = 42;
/** RegularExpression Id. */
int CHISQ = 43;
/** RegularExpression Id. */
int LAPLACE = 44;
/** RegularExpression Id. */
int CAUCHY = 45;
/** RegularExpression Id. */
int RAYLEIGH = 46;
/** RegularExpression Id. */
int POISSON = 47;
/** RegularExpression Id. */
int BINOMIAL = 48;
/** RegularExpression Id. */
int BERNOULLI = 49;
/** RegularExpression Id. */
int BITNOT = 50;
/** RegularExpression Id. */
int BITOR = 51;
/** RegularExpression Id. */
int BITAND = 52;
/** RegularExpression Id. */
int BITXOR = 53;
/** RegularExpression Id. */
int INT = 54;
/** RegularExpression Id. */
int BOOL = 55;
/** RegularExpression Id. */
int BIT = 56;
/** RegularExpression Id. */
int RATE = 57;
/** RegularExpression Id. */
int VERIFY = 58;
/** RegularExpression Id. */
int SEARCH = 59;
/** RegularExpression Id. */
int ASSIGN = 60;
/** RegularExpression Id. */
int IMPLIC = 61;
/** RegularExpression Id. */
int COMMA = 62;
/** RegularExpression Id. */
int QMARK = 63;
/** RegularExpression Id. */
int EQUAL = 64;
/** RegularExpression Id. */
int OBRACE = 65;
/** RegularExpression Id. */
int LESSTHAN = 66;
/** RegularExpression Id. */
int BOOL_FALSE = 67;
/** RegularExpression Id. */
int BOOL_TRUE = 68;
/** RegularExpression Id. */
int AU = 69;
/** RegularExpression Id. */
int EU = 70;
/** RegularExpression Id. */
int EG = 71;
/** RegularExpression Id. */
int EF = 72;
/** RegularExpression Id. */
int AG = 73;
/** RegularExpression Id. */
int AF = 74;
/** RegularExpression Id. */
int PG = 75;
/** RegularExpression Id. */
int PF = 76;
/** RegularExpression Id. */
int PU = 77;
/** RegularExpression Id. */
int PX = 78;
/** RegularExpression Id. */
int Pr = 79;
/** RegularExpression Id. */
int Ss = 80;
/** RegularExpression Id. */
int OSQUARE = 81;
/** RegularExpression Id. */
int CSQUARE = 82;
/** RegularExpression Id. */
int GREATERTHAN = 83;
/** RegularExpression Id. */
int CBRACE = 84;
/** RegularExpression Id. */
int DISABLE = 85;
/** RegularExpression Id. */
int INF = 86;
/** RegularExpression Id. */
int SYMBOL = 87;
/** RegularExpression Id. */
int ID = 88;
/** RegularExpression Id. */
int NUM = 89;
/** RegularExpression Id. */
int INTEGER = 90;
/** RegularExpression Id. */
int REAL = 91;
/** RegularExpression Id. */
int LETTER = 92;
/** RegularExpression Id. */
int DIGIT = 93;
/** RegularExpression Id. */
int PLUS = 94;
/** RegularExpression Id. */
int MINUS = 95;
/** RegularExpression Id. */
int OPAR = 96;
/** RegularExpression Id. */
int CPAR = 97;
/** RegularExpression Id. */
int MULT = 98;
/** RegularExpression Id. */
int MOD = 99;
/** RegularExpression Id. */
int POWER = 100;
/** RegularExpression Id. */
int NOT = 101;
/** RegularExpression Id. */
int DIV = 102;
/** RegularExpression Id. */
int AND = 103;
/** RegularExpression Id. */
int OR = 104;
/** RegularExpression Id. */
int GEQ = 105;
/** RegularExpression Id. */
int LEQ = 106;
/** RegularExpression Id. */
int SEMICOLON = 107;
/** RegularExpression Id. */
int UNKNOWN = 108;
/** RegularExpression Id. */
int COMMENTS = 114;
/** RegularExpression Id. */
int DELIM = 115;
/** Lexical state. */
int DEFAULT = 0;
/** Literal token values. */
String[] tokenImage = {
"<EOF>",
"\".\"",
"<ATACS>",
"<END>",
"<INPUTS>",
"<INIT_STATE>",
"<DUMMYS>",
"<FAILTRANS>",
"<VARIABLES>",
"<INTEGERS>",
"<NONINPS>",
"<KEEPS>",
"<ABSTRACTS>",
"<CONTINUOUS>",
"<RATES>",
"<INITRATES>",
"<INITVALS>",
"<INITINTS>",
"<INVARIANTS>",
"<ENABLINGS>",
"<ASSIGNS>",
"<TRANS_RATES>",
"<RATE_ASSIGNS>",
"<INT_ASSIGNS>",
"<DELAY_ASSIGNS>",
"<PRIORITY_ASSIGNS>",
"<BOOL_ASSIGNS>",
"<OUTPUTS>",
"<INTERNAL>",
"<GRAPH>",
"<PROPERTY>",
"<MARKING>",
"<NAME>",
"\"min\"",
"\"max\"",
"\"idiv\"",
"\"floor\"",
"\"ceil\"",
"\"uniform\"",
"\"normal\"",
"\"exponential\"",
"\"gamma\"",
"\"lognormal\"",
"\"chisq\"",
"\"laplace\"",
"\"cauchy\"",
"\"rayleigh\"",
"\"poisson\"",
"\"binomial\"",
"\"bernoulli\"",
"\"NOT\"",
"\"OR\"",
"\"AND\"",
"\"XOR\"",
"\"INT\"",
"\"BOOL\"",
"\"BIT\"",
"\"rate\"",
"\"verify\"",
"\"search\"",
"\":=\"",
"\"=>\"",
"\",\"",
"\"?\"",
"\"=\"",
"\"{\"",
"\"<\"",
"\"false\"",
"\"true\"",
"\"AU\"",
"\"EU\"",
"\"EG\"",
"\"EF\"",
"\"AG\"",
"\"AF\"",
"\"PG\"",
"\"PF\"",
"\"PU\"",
"\"PX\"",
"\"Pr\"",
"\"St\"",
"\"[\"",
"\"]\"",
"\">\"",
"\"}\"",
"\")d\"",
"\"inf\"",
"<SYMBOL>",
"<ID>",
"<NUM>",
"<INTEGER>",
"<REAL>",
"<LETTER>",
"<DIGIT>",
"\"+\"",
"\"-\"",
"\"(\"",
"\")\"",
"\"*\"",
"\"%\"",
"\"^\"",
"\"~\"",
"\"/\"",
"\"&\"",
"\"|\"",
"\">=\"",
"\"<=\"",
"\";\"",
"\"\\\\\"",
"\" \"",
"\"\\t\"",
"\"\\n\"",
"\"\\r\"",
"\"\\r\\n\"",
"<COMMENTS>",
"<DELIM>",
};
}

View file

@ -0,0 +1,121 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn;
import java.util.ArrayList;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Place {
private String name;
private Boolean marked;
private ArrayList<Transition> preset;
private ArrayList<Transition> postset;
public Place(String name) {
this.name = name;
marked = false;
preset = new ArrayList<Transition>();
postset = new ArrayList<Transition>();
}
public Place(String name, boolean marking) {
this.name = name;
marked = marking;
preset = new ArrayList<Transition>();
postset = new ArrayList<Transition>();
}
public void addPreset(Transition transition) {
preset.add(transition);
}
public void addPostset(Transition transition) {
postset.add(transition);
}
public void removePreset(Transition transition) {
preset.remove(transition);
}
public void removePostset(Transition transition) {
postset.remove(transition);
}
public void setMarking(boolean marking) {
marked = marking;
}
public boolean isMarked() {
return marked;
}
public boolean isConnected() {
return (preset.size() > 0 || postset.size() > 0);
}
public boolean containsPreset(String name) {
return preset.contains(name);
}
public boolean containsPostset(String name) {
return postset.contains(name);
}
public void setName(String newName) {
this.name = newName;
}
public String getName() {
return name;
}
public Transition[] getPreset() {
Transition[] array = new Transition[preset.size()];
int i = 0;
for (Transition t : preset) {
array[i++] = t;
}
return array;
}
public Transition[] getPostset() {
Transition[] array = new Transition[postset.size()];
int i = 0;
for (Transition t : postset) {
array[i++] = t;
}
return array;
}
@Override
public String toString() {
return name;
}
public void changeName(String newName){
name = newName;
}
}

View file

@ -0,0 +1,149 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
/* Generated By:JavaCC: Do not edit this line. Token.java Version 5.0 */
/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
package edu.utah.ece.async.lema.verification.lpn;
/**
* Describes the input token stream.
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Token implements java.io.Serializable {
/**
* The version identifier for this Serializable class.
* Increment only if the <i>serialized</i> form of the
* class changes.
*/
private static final long serialVersionUID = 1L;
/**
* An integer that describes the kind of this token. This numbering
* system is determined by JavaCCParser, and a table of these numbers is
* stored in the file ...Constants.java.
*/
public int kind;
/** The line number of the first character of this Token. */
public int beginLine;
/** The column number of the first character of this Token. */
public int beginColumn;
/** The line number of the last character of this Token. */
public int endLine;
/** The column number of the last character of this Token. */
public int endColumn;
/**
* The string image of the token.
*/
public String image;
/**
* A reference to the next regular (non-special) token from the input
* stream. If this is the last token from the input stream, or if the
* token manager has not read tokens beyond this one, this field is
* set to null. This is true only if this token is also a regular
* token. Otherwise, see below for a description of the contents of
* this field.
*/
public Token next;
/**
* This field is used to access special tokens that occur prior to this
* token, but after the immediately preceding regular (non-special) token.
* If there are no such special tokens, this field is set to null.
* When there are more than one such special token, this field refers
* to the last of these special tokens, which in turn refers to the next
* previous special token through its specialToken field, and so on
* until the first special token (whose specialToken field is null).
* The next fields of special tokens refer to other special tokens that
* immediately follow it (without an intervening regular token). If there
* is no such token, this field is null.
*/
public Token specialToken;
/**
* An optional attribute value of the Token.
* Tokens which are not used as syntactic sugar will often contain
* meaningful values that will be used later on by the compiler or
* interpreter. This attribute value is often different from the image.
* Any subclass of Token that actually wants to return a non-null value can
* override this method as appropriate.
*/
public static Object getValue() {
return null;
}
/**
* No-argument constructor
*/
public Token() {}
/**
* Constructs a new token for the specified Image.
*/
public Token(int kind)
{
this(kind, null);
}
/**
* Constructs a new token for the specified Image and Kind.
*/
public Token(int kind, String image)
{
this.kind = kind;
this.image = image;
}
/**
* Returns the image.
*/
@Override
public String toString()
{
return image;
}
/**
* Returns a new Token object, by default. However, if you want, you
* can create and return subclass objects based on the value of ofKind.
* Simply add the cases to the switch for all those special cases.
* For example, if you have a subclass of Token called IDToken that
* you want to create if ofKind is ID, simply add something like :
*
* case MyParserConstants.ID : return new IDToken(ofKind, image);
*
* to the following switch statement. Then you can cast matchedToken
* variable to the appropriate type and use sit in your lexical actions.
*/
public static Token newToken(int ofKind, String image)
{
switch(ofKind)
{
default : return new Token(ofKind, image);
}
}
public static Token newToken(int ofKind)
{
return newToken(ofKind, null);
}
}
/* JavaCC - OriginalChecksum=ad9059036c2df112e5851986a59467a6 (do not edit this line) */

View file

@ -0,0 +1,167 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */
/* JavaCCOptions: */
package edu.utah.ece.async.lema.verification.lpn;
/** Token Manager Error.
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class TokenMgrError extends Error
{
/**
* The version identifier for this Serializable class.
* Increment only if the <i>serialized</i> form of the
* class changes.
*/
private static final long serialVersionUID = 1L;
/*
* Ordinals for various reasons why an Error of this type can be thrown.
*/
/**
* Lexical error occurred.
*/
static final int LEXICAL_ERROR = 0;
/**
* An attempt was made to create a second instance of a static token manager.
*/
static final int STATIC_LEXER_ERROR = 1;
/**
* Tried to change to an invalid lexical state.
*/
static final int INVALID_LEXICAL_STATE = 2;
/**
* Detected (and bailed out of) an infinite loop in the token manager.
*/
static final int LOOP_DETECTED = 3;
/**
* Indicates the reason why the exception is thrown. It will have
* one of the above 4 values.
*/
int errorCode;
/**
* Replaces unprintable characters by their escaped (or unicode escaped)
* equivalents in the given string
*/
protected static final String addEscapes(String str) {
StringBuffer retval = new StringBuffer();
char ch;
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i))
{
case 0 :
continue;
case '\b':
retval.append("\\b");
continue;
case '\t':
retval.append("\\t");
continue;
case '\n':
retval.append("\\n");
continue;
case '\f':
retval.append("\\f");
continue;
case '\r':
retval.append("\\r");
continue;
case '\"':
retval.append("\\\"");
continue;
case '\'':
retval.append("\\\'");
continue;
case '\\':
retval.append("\\\\");
continue;
default:
if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) {
String s = "0000" + Integer.toString(ch, 16);
retval.append("\\u" + s.substring(s.length() - 4, s.length()));
} else {
retval.append(ch);
}
continue;
}
}
return retval.toString();
}
/**
* Returns a detailed message for the Error when it is thrown by the
* token manager to indicate a lexical error.
* Parameters :
* EOFSeen : indicates if EOF caused the lexical error
* curLexState : lexical state in which this error occurred
* errorLine : line number when the error occurred
* errorColumn : column number when the error occurred
* errorAfter : prefix that was seen before this error occurred
* curchar : the offending character
* Note: You can customize the lexical error message by modifying this method.
*/
protected static String LexicalError(boolean EOFSeen, int errorLine, int errorColumn, String errorAfter, char curChar) {
return("Lexical error at line " +
errorLine + ", column " +
errorColumn + ". Encountered: " +
(EOFSeen ? "<EOF> " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") +
"after : \"" + addEscapes(errorAfter) + "\"");
}
/**
* You can also modify the body of this method to customize your error messages.
* For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not
* of end-users concern, so you can return something like :
*
* "Internal Error : Please file a bug report .... "
*
* from this method for such cases in the release version of your parser.
*/
@Override
public String getMessage() {
return super.getMessage();
}
/*
* Constructors of various flavors follow.
*/
/** No arg constructor. */
public TokenMgrError() {
}
/** Constructor with message and reason. */
public TokenMgrError(String message, int reason) {
super(message);
errorCode = reason;
}
/** Full Constructor. */
public TokenMgrError(boolean EOFSeen, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) {
this(LexicalError(EOFSeen, errorLine, errorColumn, errorAfter, curChar), reason);
}
}
/* JavaCC - OriginalChecksum=ce3529e97c9e8097235dbae4de0edb3c (do not edit this line) */

View file

@ -0,0 +1,201 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn;
import java.util.ArrayList;
import java.util.Properties;
import edu.utah.ece.async.lema.verification.timed_state_exploration.zoneProject.InequalityVariable;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Variable {
protected String name;
private String type;
protected String initValue;
private String initRate;
private String port;
// For continuous variables, a list of inequality variables
// that contain this continuous variable.
protected ArrayList<InequalityVariable> inequalities;
public Variable(String name, String type) {
this.name = name;
this.type = type;
}
public Variable(String name, String type, String initValue) {
this.name = name;
this.type = type;
this.initValue = initValue;
}
public Variable(String name, String type, Properties initCond) {
if (type.equals(CONTINUOUS)) {
this.name = name;
this.type = type;
this.initValue = initCond.getProperty("value");
this.initRate = initCond.getProperty("rate");
}
}
public Variable(String name, String type, Properties initCond, String port) {
if (type.equals(CONTINUOUS)) {
this.name = name;
this.type = type;
this.initValue = initCond.getProperty("value");
this.initRate = initCond.getProperty("rate");
this.port = port;
}
}
public Variable(String name, String type, String initValue, String port) {
this.name = name;
this.type = type;
this.initValue = initValue;
this.port = port;
}
public void addInitValue(String initValue) {
this.initValue = initValue;
}
public void addInitRate(String initRate) {
this.initRate = initRate;
}
public void addInitCond(Properties initCond) {
if (type.equals(CONTINUOUS)) {
this.initValue = initCond.getProperty("value");
this.initRate = initCond.getProperty("rate");
}
}
public String getName() {
return name;
}
public String getInitValue() {
return initValue;
}
public String getInitRate() {
return initRate;
}
public boolean isInput() {
if (port != null) {
return port.equals(INPUT);
}
return false;
}
public boolean isOutput() {
if (port != null) {
return port.equals(OUTPUT);
}
return false;
}
public boolean isInternal() {
if (port != null) {
return port.equals(INTERNAL);
}
return true;
}
public String getPort() {
return port;
}
public String getType() {
return type;
}
public void setPort(String newPort) {
port = newPort;
}
@Override
public String toString() {
return name;
}
@Override
public boolean equals(Object var) {
return name.equals(var.toString());
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((initRate == null) ? 0 : initRate.hashCode());
result = prime * result
+ ((initValue == null) ? 0 : initValue.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((port == null) ? 0 : port.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
/**
* Get the list of inequality variables that reference this continuous
* variable.
* @return
* A list of all the inequality variables that reference this continuous
* variable.
*/
public ArrayList<InequalityVariable> getInequalities(){
return inequalities;
}
/**
* Add an inequality variable that references this continuous variable.
* @param inVar
* The InequalityVariable to add.
*/
public void addInequalityVariable(InequalityVariable inVar){
if(inequalities == null){
inequalities = new ArrayList<InequalityVariable>();
}
inequalities.add(inVar);
}
public static final String BOOLEAN = "boolean";
public static final String INTEGER = "integer";
public static final String CONTINUOUS = "continuous";
public static final String INPUT = "input";
public static final String OUTPUT = "output";
public static final String INTERNAL = "internal";
}

View file

@ -0,0 +1,136 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.lpn.properties;
import javax.swing.DefaultListModel;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class AbstractionProperty {
public String xform0 = "Merge Parallel Places - simplification",
xform1 = "Remove Place in Self-Loop - simplification",
xform3 = "Remove Transitions with Single Place in Postset - simplification",
xform4 = "Remove Transitions with Single Place in Preset - simplification",
xform5 = "Merge Transitions with Same Preset and Postset - simplification",
xform6 = "Merge Transitions with Same Preset - simplification",
xform7 = "Merge Transitions with Same Postset - simplification",
xform8 = "Local Assignment Propagation - simplification",
xform9 = "Remove Write Before Write - simplification",
xform10 = "Simplify Expressions - simplification",
xform11 = "Constant False Enabling Conditions - simplification",
xform12 = "Abstract Assignments to the Same Variable - abstraction",
xform13 = "Remove Unread Variables - abstraction",
xform14 = "Remove Dead Places - simplification",
xform15 = "Remove Dead Transitions - simplification",
xform16 = "Constant True Enabling Conditions - simplification",
xform17 = "Eliminate Dominated Transitions - simplification",
xform18 = "Remove Unread Variables - simplification",
xform19 = "Correlated Variables - simplification",
xform20 = "Remove Arc after Failure Transitions - simplification",
xform21 = "Timing Bound Normalization - abstraction",
xform22 = "Remove Vacuous Transitions - simplification",
xform23 = "Remove Vacuous Transitions - abstraction",
xform24 = "Remove Pairwise Write Before Write - simplification",
xform25 = "Propagate Constant Variable Values - simplifiction",
xform26 = "Remove Dangling Transitions - simplification",
xform27 = "Combine Parallel Transitions - simplification",
xform28 = "Combine Parallel Transitions - abstraction",
xform29 = "Remove Uninteresting Variables - simplification",
xform30 = "Remove Uninteresting Transitions - simplification",
xform31 = "Simplify Uniform Expressions - abstraction";
public String[] transforms = { xform12, xform28, xform27, xform11, xform16,
xform19, xform17, xform8, xform0, xform7, xform6, xform5, xform25, xform20,
xform26, xform14, xform15, xform24, xform1, xform3, xform4,
xform30, xform29, xform13, xform18, xform23, xform22, xform9,
xform10, xform31, xform21 };
public DefaultListModel listModel, absListModel, preAbsModel, loopAbsModel,
postAbsModel;
public String maxIter, factor, field;
boolean verification, simplify, abstractLhpn;
public AbstractionProperty()
{
listModel = new DefaultListModel();
// Creates Abstraction List
preAbsModel = new DefaultListModel();
loopAbsModel = new DefaultListModel();
postAbsModel = new DefaultListModel();
maxIter = ""; factor = ""; field = "";
simplify = true;
verification = true;
}
public String[] getIntVars() {
String[] intVars = new String[listModel.getSize()];
for (int i = 0; i < listModel.getSize(); i++) {
if (listModel.elementAt(i) != null) {
intVars[i] = listModel.elementAt(i).toString();
}
}
return intVars;
}
public void viewCircuit() {
String[] getFilename;
if (field.trim().equals("")) {
} else {
getFilename = new String[1];
getFilename[0] = field.trim();
}
}
public boolean isSimplify() {
if (verification) {
return true;
}
if (simplify
|| abstractLhpn) {
return true;
}
return false;
}
public boolean isAbstract() {
if (verification) {
return true;
}
return abstractLhpn;
}
public Integer getNormFactor() {
Integer factor;
try {
factor = Integer.parseInt(this.factor);
}
catch (NumberFormatException e) {
factor = -1;
}
return factor;
}
public Integer maxIterations() {
return Integer.parseInt(maxIter);
}
}

View file

@ -0,0 +1,396 @@
grammar Property;
options {
language = Java;
output = AST;
ASTLabelType = CommonTree;
}
@header {
package lpn.parser.properties;
//import lpn.parser.LhpnFile;
//package antlrPackage;
}
@lexer::header {
package lpn.parser.properties;
//package antlrPackage;
}
program
:property
;
property
: 'property'^ ID LCURL! (declaration)* (statement)* RCURL!
;
declaration
:BOOLEAN^ ID (COMMA! ID)* SEMICOL!
| REAL^ ID (COMMA! ID)* SEMICOL!
| INTEGER^ ID (COMMA! ID)* SEMICOL!
;
SENALWAYS
: 'senalways'
;
ALWAYS
: 'always'
;
BOOLEAN
:'boolean'
;
REAL
:'real'
;
INTEGER
:'int'
;
WAIT
:'wait'
;
WAIT_DELAY
:'waitDelay'
;
NOT
: '~'
;
MOD
:'%'
;
AND
:'&'
;
OR
:'|'
;
ASSERT
:'assert'
;
IF
:'if'
;
END
:'end'
;
ELSEIF
:'else if'
;
ELSE
:'else'
;
WAIT_STABLE
:'waitStable'
;
ASSERT_STABLE
:'assertStable'
;
ASSERT_UNTIL
:'assertUntil'
;
WAIT_POSEDGE
: 'waitPosedge'
;
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
INT : '0'..'9'+
;
FLOAT
: ('0'..'9')+ '.' ('0'..'9')* EXPONENT?
| '.' ('0'..'9')+ EXPONENT?
| ('0'..'9')+ EXPONENT
;
COMMENT
: '//' ~('\n'|'\r')* '\r'? '\n' {$channel=HIDDEN;}
| '/*' ( options {greedy=false;} : . )* '*/' {$channel=HIDDEN;}
;
WS : ( ' '
| '\t'
| '\r'
| '\n'
|'\r\n'
) {$channel=HIDDEN;}
;
STRING
: '\'' ( ESC_SEQ | ~('\\'|'\'') )* '\''
;
fragment
EXPONENT : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
fragment
HEX_DIGIT : ('0'..'9'|'a'..'f'|'A'..'F') ;
fragment
ESC_SEQ
: '\\' ('b'|'t'|'n'|'f'|'r'|'\"'|'\''|'\\')
| UNICODE_ESC
| OCTAL_ESC
;
fragment
OCTAL_ESC
: '\\' ('0'..'3') ('0'..'7') ('0'..'7')
| '\\' ('0'..'7') ('0'..'7')
| '\\' ('0'..'7')
;
fragment
UNICODE_ESC
: '\\' 'u' HEX_DIGIT HEX_DIGIT HEX_DIGIT HEX_DIGIT
;
PLUS
:'+'
;
MINUS
: '-'
;
MULT
:'*'
;
DIV
:'/'
;
DASH
:'***'
;
EQUAL
:'='
;
NOT_EQUAL
:'!='
;
GET
:'>'
;
LET
:'<'
;
GETEQ
:'>='
;
LETEQ
:'<='
;
SAMEAS
:'=='
;
LPARA
:'('
;
RPARA
:')'
;
LCURL
:'{'
;
RCURL
:'}'
;
SEMICOL
:';'
;
COMMA
:','
;
UNIFORM
:'uniform('INT','INT')'
;
booleanNegationExpression
: (NOT^)* constantValue
//: (NOT^)* (LPARA!)* relationalExpression (RPARA!)*
;
always_statement
: ALWAYS^ LCURL! (statement)* RCURL! //SEMICOL!
;
senalways_statement
: SENALWAYS^ (sensitivityList)? LCURL! (statement)* RCURL!
;
sensitivityList
: (LPARA^ ID (COMMA! ID)* RPARA!)
;
signExpression
:(PLUS^|MINUS^)* booleanNegationExpression
//:(PLUS^|MINUS^)* constantValue
;
multiplyingExpression
: signExpression ((MULT^|DIV^|MOD^) signExpression)*
;
addingExpression
: multiplyingExpression ((PLUS^|MINUS^) multiplyingExpression)*
;
relationalExpression
: addingExpression ((EQUAL^|NOT_EQUAL^|GET^|GETEQ^|LET^|LETEQ^|SAMEAS^) addingExpression)*
;
logicalExpression
: relationalExpression ((AND^|OR^) relationalExpression)*
;
//logicalExpression
// : relationalExpression ((AND^|OR^) relationalExpression)*
// ;
unaryExpression
: (NOT^)* LPARA! logicalExpression RPARA!
// : (NOT^)* logicalExpression
;
combinationalExpression
: unaryExpression ((AND^|OR^) unaryExpression)*
;
expression
//: relational
//:constantValue
//|primitiveElement
//|addingExpression
//|multiplyingExpression
//: unaryExpression
// | logicalExpression
:combinationalExpression
| logicalExpression
;
constantValue
: INT | ID | UNIFORM
;
wait_statement
: WAIT^ LPARA! expression RPARA! SEMICOL!
// | WAIT^ LPARA! expression COMMA! expression (GET expression)* RPARA! SEMICOL!
| WAIT^ LPARA! expression COMMA! expression RPARA! SEMICOL!
;
wait_delay_statement
: WAIT_DELAY^ LPARA! expression RPARA! SEMICOL!
;
assert_statement
: ASSERT^ LPARA! expression COMMA! expression RPARA! SEMICOL!
;
if_statement
: IF^ if_part
;
if_part
: LPARA!expression RPARA! LCURL! (statement)* RCURL! (else_if)* (else_part)*
;
else_if
: ELSEIF^ LPARA!expression RPARA! LCURL! (statement)* RCURL!
;
else_part
:ELSE^ LCURL! (statement)* RCURL!
;
waitStable_statement
:WAIT_STABLE^ LPARA! expression COMMA! expression RPARA! SEMICOL!
;
assertUntil_statement
:ASSERT_UNTIL^ LPARA! expression COMMA! expression RPARA! SEMICOL!
;
edge_statement
: WAIT_POSEDGE^ LPARA! expression RPARA! SEMICOL!
;
assertStable_statement
:ASSERT_STABLE^ LPARA! expression COMMA! expression RPARA! SEMICOL!
;
//waitPosedge_statement
//:WAIT_POSEDGE^ LPARA! expression RPARA! SEMICOL!
//;
statement
:wait_statement
|wait_delay_statement
|assert_statement
|if_statement
|waitStable_statement
|assertUntil_statement
|always_statement
|assertStable_statement
|edge_statement
|senalways_statement
;

View file

@ -0,0 +1,314 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.BinaryTree;
import java.util.*;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class BinaryTree {
/* Tables for storing nodes that are not root. */
HashMap<Node, Node> uniqueNodeTbl;
Vector<Node> NodeIdxTbl;
/* Tables for storing root nodes and their indices. */
HashMap<Node, Node> uniqueRootNodeTbl;
Vector<Node> rootNodeIdxTbl;
/* Size restricted fast lookup */
HashMap<Integer, int[]> lastAccessedTbl;
LinkedList<Integer> lastAccessedIdxList;
public BinaryTree() {
this.uniqueNodeTbl = new HashMap<Node, Node>();
this.NodeIdxTbl = new Vector<Node>(100);
this.uniqueRootNodeTbl = new HashMap<Node, Node>();
this.rootNodeIdxTbl = new Vector<Node>(100);
lastAccessedTbl = new HashMap<Integer, int[]>();
lastAccessedIdxList = new LinkedList<Integer>();
}
/*
* Build a binary tree for IdxArray.
* Return the the literal of the root node.
*/
public int add(int[] IdxArray) {
if(IdxArray == null)
return -1;
//System.out.println("add " + Arrays.toString(IdxArray));
int[] nodeLitArray = IdxArray;
int[] attributeArray = new int[IdxArray.length];
for (int i = 0; i < IdxArray.length; i++) {
attributeArray[i] = 1;
}
while (nodeLitArray.length > 1) {
int lastSlot = nodeLitArray[nodeLitArray.length - 1];
int lastAttribute = attributeArray[attributeArray.length-1];
boolean arrayLenOdd = true;
if ((nodeLitArray.length & 1) == 0)
arrayLenOdd = false;
int pairCnt = nodeLitArray.length >> 1;
int[] newnodeLitArray = null;
int[] newattributeArray = null;
if (arrayLenOdd == true) {
newnodeLitArray = new int[pairCnt + 1];
newattributeArray = new int[pairCnt + 1];
} else {
newnodeLitArray = new int[pairCnt];
newattributeArray = new int[pairCnt];
}
for (int i = 0; i < pairCnt; i++) {
Node newNode = new Node();
newNode.setLeft(nodeLitArray[i*2]);
newNode.setRight(nodeLitArray[i*2 + 1]);
char terminal = 0x00;
if(attributeArray[i*2]==1) {
terminal = (char)(terminal | 0xF0);
}
if(attributeArray[i*2+1]==1) {
terminal = (char)(terminal | 0x0F);
}
newNode.setTerminal(terminal);
/* If nodeLitArray has more than 2 literals, newNode, which is not a root node, is added by calling addNode().
* Otherwise, newNode is a root node, and added by calling addRootNode(). */
int newNodeLit = nodeLitArray.length > 2 ? this.addNode(newNode) : this.addRootNode(newNode);
newnodeLitArray[i] = newNodeLit;
newattributeArray[i] = 0;
}
if (arrayLenOdd == true) {
newnodeLitArray[pairCnt] = lastSlot;
newattributeArray[pairCnt] = lastAttribute;
}
nodeLitArray = newnodeLitArray;
attributeArray = newattributeArray;
}
//System.out.println("add node lit = " + nodeLitArray[0] + "\n");
//System.out.println("added vec = " + Arrays.toString(this.toIntArray(nodeLitArray[0])) + "\n");
int rootLit = nodeLitArray[0];
if(this.lastAccessedTbl.containsKey(rootLit) == false) {
if(this.lastAccessedIdxList.size() > 1000000) {
int oldestIdx = this.lastAccessedIdxList.removeFirst();
this.lastAccessedTbl.remove(oldestIdx);
}
this.lastAccessedIdxList.addLast(rootLit);
this.lastAccessedTbl.put(rootLit, IdxArray);
}
return rootLit;
}
public boolean contains(int[] IdxArray) {
//System.out.println("check " + Arrays.toString(IdxArray));
int[] nodeLitArray = IdxArray;
int[] attributeArray = new int[IdxArray.length];
for (int i = 0; i < IdxArray.length; i++) {
attributeArray[i] = 1;
}
while (nodeLitArray.length > 1) {
int lastSlot = nodeLitArray[nodeLitArray.length - 1];
int lastAttribute = attributeArray[attributeArray.length-1];
boolean arrayLenOdd = true;
if ((nodeLitArray.length & 1) == 0)
arrayLenOdd = false;
int pairCnt = nodeLitArray.length >> 1;
int[] newnodeLitArray = null;
int[] newattributeArray = null;
if (arrayLenOdd == true) {
newnodeLitArray = new int[pairCnt + 1];
newattributeArray = new int[pairCnt + 1];
} else {
newnodeLitArray = new int[pairCnt];
newattributeArray = new int[pairCnt];
}
for (int i = 0; i < pairCnt; i++) {
Node newNode = new Node();
newNode.setLeft(nodeLitArray[i*2]);
newNode.setRight(nodeLitArray[i*2 + 1]);
char terminal = 0x00;
if(attributeArray[i*2]==1)
terminal = (char)(terminal | 0xF0);
if(attributeArray[i*2+1]==1)
terminal = (char)(terminal | 0x0F);
newNode.setTerminal(terminal);
int newNodeLit = pairCnt > 1 ? this.getNodeLit(newNode) : this.getRootNodeLit(newNode);
if(newNodeLit == -1) {
return false;
}
newnodeLitArray[i] = newNodeLit;
newattributeArray[i] = 0;
}
if (arrayLenOdd == true) {
newnodeLitArray[pairCnt] = lastSlot;
newattributeArray[pairCnt] = lastAttribute;
}
nodeLitArray = newnodeLitArray;
attributeArray = newattributeArray;
}
return nodeLitArray[0] == -1 ? false : true;
}
public int[] toIntArray(int nodeLit) {
int[] tmp = this.lastAccessedTbl.get(nodeLit);
if(tmp != null)
return tmp;
boolean flipped = ((nodeLit & 1) == 1);
Node rootNode = this.getRootNode(nodeLit);
if(rootNode==null)
return null;
LinkedList<Integer> IntList = rootNode.toIntArray(this, flipped);
int[] result = new int[IntList.size()];
int pos = 0;
while(IntList.size() > 0) {
result[pos] = IntList.removeFirst();
pos++;
}
return result;
}
private int addNode(Node node) {
int nodeLit = this.getNodeLit(node);
if (nodeLit != -1)
return nodeLit;
int idx = this.uniqueNodeTbl.size()+1;
node.setIndex(idx);
this.uniqueNodeTbl.put(node, node);
if(idx >= this.NodeIdxTbl.size()) {
this.NodeIdxTbl.setSize(this.NodeIdxTbl.size() + 100);
}
this.NodeIdxTbl.setElementAt(node, idx);
return (idx << 1);
}
private int addRootNode(Node node) {
int nodeLit = this.getRootNodeLit(node);
if (nodeLit != -1)
return nodeLit;
int idx = this.uniqueRootNodeTbl.size()+1;
node.setIndex(idx);
this.uniqueRootNodeTbl.put(node, node);
if(idx >= this.rootNodeIdxTbl.size()) {
this.rootNodeIdxTbl.setSize(this.rootNodeIdxTbl.size() + 100);
}
this.rootNodeIdxTbl.setElementAt(node, idx);
return (idx << 1);
}
public Node getNode(int nodeLit) {
int nodeIdx = nodeLit >> 1;
return this.NodeIdxTbl.get(nodeIdx);
}
public Node getRootNode(int nodeLit) {
int nodeIdx = nodeLit >> 1;
return this.rootNodeIdxTbl.get(nodeIdx);
}
/*
* Check if 'node' exists in the node table. If yes, return the node
* literal. If the node complement exists, return its literal as well.
* Otherwise, return -1.
*/
public int getNodeLit(Node node) {
Node cachedNode = this.uniqueNodeTbl.get(node);
if (cachedNode != null) {
int idx = cachedNode.getIndex();
return idx << 1;
}
Node flipNode = node.flip();
Node cachedFlipNode = this.uniqueNodeTbl.get(flipNode);
if (cachedFlipNode != null) {
int idx = cachedFlipNode.getIndex();
return (idx << 1) + 1;
}
return -1;
}
public int getRootNodeLit(Node node) {
Node cachedNode = this.uniqueRootNodeTbl.get(node);
if (cachedNode != null) {
int idx = cachedNode.getIndex();
return idx << 1;
}
Node flipNode = node.flip();
Node cachedFlipNode = this.uniqueRootNodeTbl.get(flipNode);
if (cachedFlipNode != null) {
int idx = cachedFlipNode.getIndex();
return (idx << 1) + 1;
}
return -1;
}
public int nodeCount() {
return this.uniqueNodeTbl.size();
}
public int elementCount() {
return this.uniqueRootNodeTbl.size();
}
@Override
public String toString() {
return "BinaryTree [uniqueNodeTbl=" + this.NodeIdxTbl + "]";
}
}

View file

@ -0,0 +1,180 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.BinaryTree;
import java.util.*;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Node {
int LeftLit;
int RightLit;
int index;
char terminal;
public Node() {
this.LeftLit = -1;
this.RightLit = -1;
this.index = -1;
this.terminal = 0x11;
}
public void setLeft(int lit) {
this.LeftLit = lit;
}
public void setRight(int lit) {
this.RightLit = lit;
}
public int getLeft() {
return this.LeftLit;
}
public int getRight() {
return this.RightLit;
}
public void setIndex(int idx) {
this.index = idx;
}
public int getIndex() {
return this.index;
}
public void setTerminal(char terminal) {
this.terminal = terminal;
}
public Node flip() {
Node flipNode = new Node();
flipNode.LeftLit = this.RightLit;
flipNode.RightLit = this.LeftLit;
if(this.terminal==0xF0)
flipNode.terminal = 0x0F;
else if(this.terminal==0x0F)
flipNode.terminal = 0xF0;
else if(this.terminal!=0xFF && this.terminal!=0x00) {
System.out.println("*** Wrong value for binary tree Node.terminal " + this.terminal);
System.exit(0);
}
return flipNode;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + LeftLit;
result = prime * result + RightLit;
result = prime * result + terminal;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Node other = (Node) obj;
if (LeftLit != other.LeftLit)
return false;
if (RightLit != other.RightLit)
return false;
if (terminal != other.terminal)
return false;
return true;
}
public char isTerminal() {
return this.terminal;
}
public LinkedList<Integer> toIntArray(BinaryTree tree, boolean flipped) {
int lLit = this.LeftLit;
int rLit = this.RightLit;
if(flipped==true) {
lLit = this.RightLit;
rLit = this.LeftLit;
}
LinkedList<Integer> lIntList = null;
LinkedList<Integer> rIntList = null;
if(this.terminal != 0xFF) {
if((this.terminal & 0xF0) == 0x00) { // left is not a terminal
Node leftNode = tree.getNode(lLit);
boolean leftFlipped = ((lLit & 1) == 1);
lIntList = leftNode.toIntArray(tree, leftFlipped);
if(this.terminal==0x0F) {
lIntList.addLast(rLit);
return lIntList;
}
}
if((this.terminal & 0x0F) == 0x00) { // right is not a terminal
Node rightNode = tree.getNode(rLit);
boolean rightFlipped = ((rLit & 1) == 1);
rIntList = rightNode.toIntArray(tree, rightFlipped);
if(this.terminal==0xF0) {
rIntList.addLast(lLit);
return rIntList;
}
}
// Case: this.terminal==0x00
while(rIntList!=null && lIntList != null && rIntList.size() > 0) {
int number = rIntList.removeFirst();
lIntList.addLast(number);
}
return lIntList;
}
LinkedList<Integer> result = new LinkedList<Integer>();
result.addLast(lLit);
result.addLast(rLit);
return result;
}
@Override
public String toString() {
String terminalStr = "";
if(this.terminal==0xF0)
terminalStr = "0xF0";
else if(this.terminal==0x0F)
terminalStr = "0x0F";
else if(this.terminal==0xFF)
terminalStr = "0xFF";
else if(this.terminal==0x00)
terminalStr = "0x00";
else
terminalStr = "xxxx";
return "Node [Left=" + LeftLit + ", Right=" + RightLit + ", index=" + index + ", terminal=" + terminalStr + "]";
}
}

View file

@ -0,0 +1,83 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.MDD;
import java.util.*;
import edu.utah.ece.async.lema.verification.platu.stategraph.*;
/**
* This data structure cannot be used as stack as it allows node sharing.
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class MDT {
static mdtNode terminal = new mdtNode();
private mdtNode root;
//private int stateCount;
//private int peakNodes;
int height;
int Size;
/*
* Initialize MDD with the number of modules in the design model.
*/
public MDT(int levels) {
root = new mdtNode();
//stateCount = 0;
height = levels;
//peakNodes = 0;
}
public void push(State[] curIdxArray) {
root.push(curIdxArray, 0);
this.Size++;
}
public State[] pop() {
this.Size--;
State[] results = new State[this.height];
return root.pop(results);
}
public Stack<State[]> popList() {
this.Size--;
State[] results = new State[this.height];
return root.popList(results);
}
// public State[] peek() {
// return root.peek(0);
// }
public boolean contains(State[] stateArray) {
return root.contains(stateArray, 0);
}
public boolean empty() {
return root.empty();
}
public int size() {
return this.Size;
}
public int nodeCnt() {
return root.nodeCnt();
}
}

View file

@ -0,0 +1,183 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.MDD;
import java.util.*;
import edu.utah.ece.async.lema.verification.platu.stategraph.*;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Mdd {
static mddNode terminal = new mddNode();
//private int stateCount;
private HashMap<mddNode, mddNode>[] nodeTbl;
private HashMap<State, HashSet<State>>[] localFirings;
private int peakNodes;
int height;
/*
* Initialize MDD with the number of modules in the design model.
*/
@SuppressWarnings("unchecked")
public Mdd(int numMods) {
Mdd.terminal.level = numMods;
//stateCount = 0;
height = numMods;
nodeTbl = new HashMap[height];
localFirings = new HashMap[height+1];
for(int i = 0; i < this.height; i++) {
nodeTbl[i] = new HashMap<mddNode, mddNode>();
localFirings[i] = new HashMap<State, HashSet<State>>();
}
peakNodes = 0;
}
public static mddNode newNode() {
return new mddNode(0);
}
/*
* Return a MDD node that is the root of MDD representing the union of states encoded in MDD 'target' and MDD 'source'
*/
public mddNode union(mddNode target, mddNode source) {
HashMap<mddNode, HashMap<mddNode, mddNode>> unionCache = new HashMap<mddNode, HashMap<mddNode, mddNode>>();
mddNode unionResult = target.union(source, nodeTbl, unionCache);
return unionResult;
}
/*
* create a MDD for stateArray. The nodes in the created MDD are added into the nodeTbl.
*/
public boolean add(mddNode target, int[] idxArray) {
target = target.add(idxArray, nodeTbl, 20);
int curNodes = 0;
for(int i = 0; i < this.height; i++)
curNodes += nodeTbl[i].size();
if(curNodes > peakNodes)
peakNodes = curNodes;
//stateCount++;
return true;
}
public boolean add(mddNode target, int[] idxArray, boolean sharing) {
if(sharing==true)
target.add(idxArray, nodeTbl, 20);
else
target.add(idxArray);
return true;
}
public void compress(mddNode target) {
target.compress(nodeTbl);
}
public mddNode doLocalFirings(StateGraph[] curLpnArray, State[] curStateArray, mddNode reachSet) {
mddNode result = Mdd.newNode();
@SuppressWarnings("unchecked")
LinkedList<State>[] nextSetArray = (new LinkedList[curLpnArray.length]);
for(int i = 0; i < curLpnArray.length; i++)
nextSetArray[i] = new LinkedList<State>();
// Do firings of local LPN transition.
mddNode newResult = result.doLocalFirings(curLpnArray, curStateArray, nextSetArray, reachSet, nodeTbl);
if(newResult == result)
return result;
this.remove(result);
return newResult;
}
public void remove(mddNode target) {
target.remove(nodeTbl);
if(target.refCount<=0)
nodeTbl[0].remove(target);
}
/*
* Check if there is a path in MDD that corresponds to stateArray. Return true if so.
*/
public static boolean contains(mddNode target, int[] idxArray) {
if(target == null)
return false;
return target.contains(idxArray)==Mdd.terminal;
}
public int[] next(mddNode curNode) {
if(curNode == null)
return null;
return curNode.next(height);
}
public int[] next(mddNode curNode, int[] curIdxArray) {
if(curIdxArray == null)
return curNode.next(height);
return curNode.next(height, curIdxArray);
}
public static double numberOfStates(mddNode target) {
HashSet<mddNode> uniqueNodes = new HashSet<mddNode>();
double paths = target.pathCount(uniqueNodes);
return paths;
}
public int nodeCnt() {
int curNodes = 0;
for(int i = 0; i < this.height; i++)
curNodes += nodeTbl[i].size();
return curNodes;
}
public HashMap<State, HashSet<State>>[] getLocalFiringTbl() {
return localFirings;
}
/*
* Returns the largest number of MDD nodes created when this MDD is live.
*/
public int peakNodeCnt() {
return peakNodes;
}
public void check()
{
for(int i = 0; i < this.height; i++) {
Set entries = nodeTbl[i].entrySet();
Iterator it = entries.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
mddNode tmp = (mddNode)entry.getKey();
System.out.println("nodeTbl@" + i + " >>> " + tmp + ": level = " + tmp.level + ", refCount = " + tmp.refCount);
//+ ", " + tmp.nodeMapSize);
}
}
}
}

View file

@ -0,0 +1,824 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.MDD;
import java.util.*;
import edu.utah.ece.async.lema.verification.lpn.Transition;
import edu.utah.ece.async.lema.verification.platu.stategraph.State;
import edu.utah.ece.async.lema.verification.platu.stategraph.StateGraph;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class mddNode {
static int blockSize = 8;
static int numBlocks = 16;
static int blockIdxMask = 15;
static int arrayIdxoffset = 4;
int level;
private mddNode[][] nodeMap;
private int[] blkHashVal;
int refCount;
int hashVal;
int nodeMapSize;
int maxArrayBound;
public mddNode() {
this.reset();
}
public mddNode(int thisLevel) {
this.reset();
level = thisLevel;
}
private void reset() {
level = -1;
nodeMap = new mddNode[numBlocks][blockSize];
this.blkHashVal = new int[numBlocks];
for(int i = 0; i < numBlocks; i++){
this.nodeMap[i] = null;
this.blkHashVal[i] = 0;
}
refCount = 0;
hashVal = 0;
nodeMapSize = 0;
maxArrayBound = -1;
}
private mddNode split() {
mddNode copy = new mddNode();
copy.level = this.level;
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
if(this.nodeMap[blkIter] == null)
continue;
for(int arrayIter = 0; arrayIter < this.nodeMap[blkIter].length; arrayIter++) {
mddNode succ = this.getSucc(blkIter, arrayIter);
if(succ != null)
copy.addSucc(blkIter, arrayIter, succ);
}
copy.blkHashVal[blkIter] = this.blkHashVal[blkIter];
}
copy.refCount = 0;
copy.hashVal = this.hashVal;
return copy;
}
/**
* Add an integer tuple into MDD root at this node.
* Isomorphic nodes are not shared.
*
* @param idxArray
* @return null if input idxArray is added into the MDD, root node otherwise.
*/
public mddNode add(int[] idxArray) {
if(this.level == -1) {
System.out.println("level is not right 1");
System.exit(0);
}
int curIdx = idxArray[this.level];
int stateIdx = curIdx;
int blockIdx = stateIdx & mddNode.blockIdxMask;
int arrayIdx = stateIdx >> mddNode.arrayIdxoffset;
mddNode nextNode = this.getSucc(blockIdx, arrayIdx);
if(nextNode == null) {
if(this.level == idxArray.length-1) {
this.addSucc(blockIdx, arrayIdx, Mdd.terminal);
this.blkHashVal[blockIdx] = Integer.rotateLeft(Arrays.hashCode(this.nodeMap[blockIdx]), this.level);
this.hashVal = 0;
return null;
}
nextNode = new mddNode();
nextNode.level = this.level + 1;
nextNode.add(idxArray);
this.addSucc(blockIdx, arrayIdx, nextNode);
this.blkHashVal[blockIdx] = Integer.rotateLeft(Arrays.hashCode(this.nodeMap[blockIdx]), this.level);
this.hashVal = 0;
return null;
}
if(nextNode == Mdd.terminal)
return this;
else if(nextNode.add(idxArray)==null)
return null;
return this;
}
public mddNode add(int[] idxArray, HashMap<mddNode, mddNode>[] nodeTbl, int shrLevel) {
if(this.level == -1) {
System.out.println("level is not right 1");
System.exit(0);
}
int curIdx = idxArray[this.level];
int stateIdx = curIdx;
int blockIdx = stateIdx & mddNode.blockIdxMask;
int arrayIdx = stateIdx >> mddNode.arrayIdxoffset;
mddNode nextNode = this.getSucc(blockIdx, arrayIdx);
if(nextNode == null) {
if(this.level == idxArray.length-1) {
nodeTbl[this.level].remove(this);
this.addSucc(blockIdx, arrayIdx, Mdd.terminal);
this.blkHashVal[blockIdx] = Integer.rotateLeft(Arrays.hashCode(this.nodeMap[blockIdx]), this.level);
this.hashVal = 0;
mddNode newThisNode = nodeTbl[this.level].get(this);
if(newThisNode != null) {
return newThisNode;
}
nodeTbl[this.level].put(this, this);
return this;
}
nextNode = new mddNode();
nextNode.level = this.level + 1;
mddNode newNextNode = nextNode.add(idxArray, nodeTbl, shrLevel);
if(newNextNode != nextNode)
nextNode = newNextNode;
nextNode.refCount++;
if(level < shrLevel)
nodeTbl[this.level].remove(this);
this.addSucc(blockIdx, arrayIdx, nextNode);
this.blkHashVal[blockIdx] = Integer.rotateLeft(Arrays.hashCode(this.nodeMap[blockIdx]), this.level);
this.hashVal = 0;
if(level < shrLevel) {
mddNode newThis = nodeTbl[this.level].get(this);
if (newThis != null) {
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
if(this.nodeMap[blkIter] == null)
continue;
for(int arrayIter = 0; arrayIter < this.nodeMap[blkIter].length; arrayIter++)
if(this.nodeMap[blkIter][arrayIter] != null)
this.nodeMap[blkIter][arrayIter].refCount--;
}
return newThis;
}
nodeTbl[this.level].put(this, this);
}
return this;
}
else if(nextNode == Mdd.terminal) {
//System.out.println("mddNode: should not reach here. Abort!");
//System.exit(0);
return Mdd.terminal;
}
else {
mddNode newNextNode = nextNode;
if(nextNode.refCount > 1) {
newNextNode = nextNode.split();//new mddNode(nextNode);
nextNode.refCount--;
// for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
// if(nextNode.nodeMap[blkIter] == null)
// continue;
//
// for(int arrayIter = 0; arrayIter < nextNode.nodeMap[blkIter].length; arrayIter++)
// if(nextNode.nodeMap[blkIter][arrayIter] != null)
// nextNode.nodeMap[blkIter][arrayIter].refCount++;
// }
mddNode newNextNode_1 = newNextNode.add(idxArray, nodeTbl, shrLevel);
if (newNextNode_1 != newNextNode)
newNextNode = newNextNode_1;
}
else {
newNextNode = nextNode.add(idxArray, nodeTbl, shrLevel);
// if no next node is splitted and the next node does not have equivalent,
// do nothing further.
if(newNextNode == nextNode)
return this;
nextNode.refCount--;
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
if(nextNode.nodeMap[blkIter] == null)
continue;
for(int arrayIter = 0; arrayIter < nextNode.nodeMap[blkIter].length; arrayIter++)
if(nextNode.nodeMap[blkIter][arrayIter] != null)
nextNode.nodeMap[blkIter][arrayIter].refCount++;
}
}
if(level < shrLevel)
nodeTbl[this.level].remove(this);
newNextNode.refCount++;
this.addSucc(blockIdx, arrayIdx, newNextNode);
this.blkHashVal[blockIdx] = Integer.rotateLeft(Arrays.hashCode(this.nodeMap[blockIdx]), this.level);
this.hashVal = 0;
if(level < shrLevel) {
mddNode newThis = nodeTbl[this.level].get(this);
if (newThis != null) {
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
if(this.nodeMap[blkIter] == null)
continue;
for(int arrayIter = 0; arrayIter < this.nodeMap[blkIter].length; arrayIter++)
if(this.nodeMap[blkIter][arrayIter] != null)
this.nodeMap[blkIter][arrayIter].refCount--;
}
return newThis;
}
nodeTbl[this.level].put(this, this);
}
return this;
}
}
public static int numCalls = 0;
public static int cacheNodes = 0;
public static int splits_level1 = 0;
public static int splits_level2 = 0;
public static int splits_level3 = 0;
public mddNode union(final mddNode other, HashMap<mddNode, mddNode>[] nodeTbl, HashMap<mddNode, HashMap<mddNode, mddNode>> unionCache) {
numCalls++;
mddNode thisCopy = this.split();
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
if(other.nodeMap[blkIter] == null)
continue;
for(int arrayIter = 0; arrayIter < other.nodeMap[blkIter].length; arrayIter++) {
mddNode thisSucc = this.getSucc(blkIter, arrayIter);
mddNode otherSucc = other.getSucc(blkIter, arrayIter);
if(otherSucc == null)
continue;
if(thisSucc == null) {
thisCopy.addSucc(blkIter, arrayIter, otherSucc);
continue;
}
// When successors are terminals, return.
if(thisSucc == Mdd.terminal || otherSucc == Mdd.terminal)
continue;
if(thisSucc==otherSucc || otherSucc.subSet(thisSucc) == true)
continue;
mddNode succCached = null;
HashMap<mddNode, mddNode> second = unionCache.get(thisSucc);
if(second != null) {
succCached = second.get(otherSucc);
}
if(succCached == null) {
mddNode succUnion = thisSucc.union(otherSucc, nodeTbl, unionCache);
// Add newSucc into the cache to avoid call union(thisSuccOriginal, otherSucc) again.
HashMap<mddNode, mddNode> secondCache = unionCache.get(thisSucc);
cacheNodes++;
if(secondCache == null) {
secondCache = new HashMap<mddNode, mddNode>();
secondCache.put(otherSucc, succUnion);
unionCache.put(thisSucc, secondCache);
}
else
secondCache.put(otherSucc, succUnion);
succCached = succUnion;
}
thisSucc.remove(nodeTbl);
thisCopy.addSucc(blkIter, arrayIter, succCached);
}
}
mddNode result = nodeTbl[thisCopy.level].get(thisCopy);
if(result == null) {
nodeTbl[thisCopy.level].put(thisCopy, thisCopy);
return thisCopy;
}
thisCopy.remove(nodeTbl);
return result;
}
public mddNode compress(HashMap<mddNode, mddNode>[] nodeTbl) {
int mddHeight = nodeTbl.length;
if(this.level < mddHeight-1) {
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
if(this.nodeMap[blkIter] == null)
continue;
for(int arrayIter = 0; arrayIter < this.nodeMap[blkIter].length; arrayIter++) {
mddNode nextNode = this.nodeMap[blkIter][arrayIter];
if(nextNode == null)
continue;
mddNode newNextNode = nextNode.compress(nodeTbl);
if(newNextNode != nextNode) {
this.addSucc(blkIter, arrayIter, newNextNode);
}
}
}
}
mddNode newThis = nodeTbl[this.level].get(this);
if(newThis == null) {
nodeTbl[this.level].put(this, this);
return this;
}
else if(newThis != this)
return newThis;
return this;
}
/*
* Recursively remove this nodes and its successor nodes from nodeTbl if their reference
* count is 0.
*/
public void remove(HashMap<mddNode, mddNode>[] nodeTbl) {
int mddHeight = nodeTbl.length;
this.refCount--;
if(this.refCount > 0)
return;
if(this.level < mddHeight) {
if(this.level < mddHeight - 1) {
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
if(this.nodeMap[blkIter] == null)
continue;
for(int arrayIter = 0; arrayIter < this.nodeMap[blkIter].length; arrayIter++) {
mddNode thisSucc = this.getSucc(blkIter, arrayIter);
if(thisSucc == null)
continue;
thisSucc.remove(nodeTbl);
}
}
}
nodeTbl[this.level].remove(this);
}
}
/**
* Check if stateArray already exists in MDD.
* @param stateArray
* @param index
* @param terminal
* @return true if stateArray exists in MDD, false otherwise.
*/
public mddNode contains(int[] idxArray) {
if(this.level == -1) {
System.out.println("level is not right 2");
System.exit(0);
}
int curIdx = idxArray[this.level];
int blockIdx = curIdx & mddNode.blockIdxMask;
int arrayIdx = curIdx >> mddNode.arrayIdxoffset;
mddNode nextNode = this.getSucc(blockIdx, arrayIdx);
if (nextNode == null)
return null;
if (nextNode == Mdd.terminal)
return Mdd.terminal;
return nextNode.contains(idxArray);
}
/*
* Exhaustively fire all local LPN transitions from each local state in curStateArray
*/
public mddNode doLocalFirings(StateGraph[] curLpnArray, State[] curStateArray,
LinkedList<State>[] nextSetArray,
mddNode reachSet,
HashMap<mddNode, mddNode>[] nodeTbl) {
int curBlkIdx = curStateArray[this.level].getIndex() & mddNode.blockIdxMask;
int curArrayIdx = curStateArray[this.level].getIndex() >> mddNode.arrayIdxoffset;
mddNode succ = Mdd.terminal;
if(this.level == curLpnArray.length - 1) {
this.addSucc(curBlkIdx, curArrayIdx, succ);
}
else if(this.level < curLpnArray.length) {
succ = new mddNode();
succ.level = this.level + 1;
mddNode newSucc = succ.doLocalFirings(curLpnArray, curStateArray, nextSetArray, reachSet, nodeTbl);
this.addSucc(curBlkIdx, curArrayIdx, newSucc);
succ = newSucc;
}
/*
* Do exhaustive local firings at this level.
*/
StateGraph curLpn = curLpnArray[this.level];
State curState = curStateArray[this.level];
// HashMap<State, State> curLocalStateSet = localStateSets[this.level];
nextSetArray[this.level].addLast(curState);
LinkedList<Transition> curEnabled = curLpn.getEnabled(curState);
LinkedList<Transition> localTranSet = new LinkedList<Transition>();
if(curEnabled != null) {
for(Transition firedTran : curEnabled)
if(firedTran.isLocal()==true)
localTranSet.addLast(firedTran);
}
if(localTranSet.size() == 0) {
mddNode newThis = nodeTbl[this.level].get(this);
if(newThis == null) {
nodeTbl[this.level].put(this, this);
return this;
}
this.remove(nodeTbl);
return newThis;
}
HashSet<State> curLocalNewStates = new HashSet<State>();
Stack<State> stateStack = new Stack<State>();
Stack<LinkedList<Transition>> enabledStack = new Stack<LinkedList<Transition>>();
stateStack.push(curState);
enabledStack.push(localTranSet);
//LinkedList<State[]> nextSet_tmp = new LinkedList<State[]>();
while(stateStack.size() != 0) {
curState = stateStack.pop();
LinkedList<Transition> curLocalEnabled = enabledStack.pop();
for(Transition tran2fire : curLocalEnabled) {
System.out.println("tran2fire = " + tran2fire.getLabel() + " in curlocalState = " + curState.getLabel());
// TODO: Need to fix this.
State nextState = null; //tran2fire.fire(curLpnArray[tran2fire.getLpn().getIndex()], curState);
// System.out.println("1 nextLocalState = " + nextState.getLabel());
if(curLocalNewStates.contains(nextState) == true)
continue;
// System.out.println("2 nextLocalState = " + nextState.getLabel());
curEnabled = curLpn.getEnabled(curState);
LinkedList<Transition> nextEnabled = curLpn.getEnabled(nextState);
// TODO: Need to fix this.
//Transition disabledTran = null; //tran2fire.disablingError(curEnabled, nextEnabled);
/*
if(disabledTran != null) {
System.err.println("Verification failed: disabling error: "
+ disabledTran.getFullLabel() + " is disabled by "
+ tran2fire.getFullLabel() + "!");
System.exit(0);
}
*/
//System.out.println("addlocal nextLocalState = " + nextState.getLabel());
curLocalNewStates.add(nextState);
// TODO: had to remove because nextState is null
//int nextBlkIdx = nextState.getIndex() & mddNode.blockIdxMask;
//int nextArrayIdx = nextState.getIndex() >> mddNode.arrayIdxoffset;
//this.addSucc(nextBlkIdx, nextArrayIdx, succ);
LinkedList<Transition> nextLocalEnabled = new LinkedList<Transition>();
//boolean nonLocalNext = false;
for(Transition tran : nextEnabled) {
if(tran.isLocal()==true)
nextLocalEnabled.addLast(tran);
//else
//nonLocalNext = true;
}
// TODO: had to remove because nextState is null
//nextState.hasNonLocalEnabled(nonLocalNext);
//nextSetArray[this.level].addLast(nextState);
if(nextLocalEnabled.size() == 0)
continue;
stateStack.push(nextState);
enabledStack.push(nextLocalEnabled);
//System.out.println("added state " + nextState.getLabel() + " into localNewStateSet");
// for(int i = 0; i < curStateArray.length; i++)
// System.out.print(newNextStateArray[i].getLabel()+", ");
// System.out.println("\n#####################");
}
}
mddNode newThis = nodeTbl[this.level].get(this);
if(newThis == null) {
nodeTbl[this.level].put(this, this);
return this;
}
this.remove(nodeTbl);
return newThis;
}
/*
* Return the successor node with index exists in nodeMap.
*/
private mddNode getSucc(int blockIdx, int arrayIdx) {
if(this.nodeMap[blockIdx]==null || arrayIdx >= this.nodeMap[blockIdx].length)
return null;
return this.nodeMap[blockIdx][arrayIdx];
}
/*
* Insert a succNode with index into the nodeMap, whose size is automatically adjusted.
*/
private boolean addSucc(int blockIdx, int arrayIdx, mddNode succNode) {
//int oldsize = nodeMap.length;
//boolean newState = false;
if(this.nodeMap[blockIdx]==null || arrayIdx >= this.nodeMap[blockIdx].length) {
this.resizeNodeMap(blockIdx, arrayIdx);
//newState = true;
//System.out.println(this + " >>> node level = " + level + " state label = " + index + " " + oldsize + " " + this.nodeMap.length);
}
this.nodeMap[blockIdx][arrayIdx] = succNode;
succNode.refCount++;
this.blkHashVal[blockIdx] = Integer.rotateLeft(Arrays.hashCode(this.nodeMap[blockIdx]), this.level);
this.hashVal = 0;
nodeMapSize++;
return true;
}
/*
* Resize the nodeMap so that an element with 'index' can be inserted into the nodeMap.
*/
private void resizeNodeMap(int blockIdx, int arrayIdx) {
if(this.nodeMap[blockIdx] == null) {
int newBlockSize = (arrayIdx / mddNode.blockSize + 1) * mddNode.blockSize;
try {
this.nodeMap[blockIdx] = new mddNode[newBlockSize];
for (int i = 0; i < newBlockSize; i++) {
this.nodeMap[blockIdx][i] = null;
}
} catch (Exception e) {
String errorMessage = String.format(
"blockIdx=%s, arrayIdx=%s, newBlockSize=%s\n",
blockIdx, arrayIdx,newBlockSize);
throw new RuntimeException(errorMessage, e);
}
}
else if(arrayIdx >= this.nodeMap[blockIdx].length) {
int newBlockSize = (arrayIdx / mddNode.blockSize + 1) * mddNode.blockSize;
mddNode[] newBlock = new mddNode[newBlockSize];
for(int i = 0; i < newBlock.length; i++) {
if(i < this.nodeMap[blockIdx].length)
newBlock[i] = this.nodeMap[blockIdx][i];
else
newBlock[i] = null;
}
this.nodeMap[blockIdx] = newBlock;
}
}
@Override
public boolean equals(Object other) {
mddNode otherNode = (mddNode)other;
if(level != otherNode.level)
return false;
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
if(this.nodeMap[blkIter] == null && otherNode.nodeMap[blkIter] == null)
continue;
if(this.nodeMap[blkIter] == null && otherNode.nodeMap[blkIter] != null)
return false;
if(this.nodeMap[blkIter] != null && otherNode.nodeMap[blkIter] == null)
return false;
if(this.nodeMap[blkIter].length != otherNode.nodeMap[blkIter].length)
return false;
for(int arrayIter = 0; arrayIter < this.nodeMap[blkIter].length; arrayIter++)
if(this.nodeMap[blkIter][arrayIter] != otherNode.nodeMap[blkIter][arrayIter])
return false;
}
return true;
}
@Override
public int hashCode() {
if(hashVal == 0)
hashVal = Arrays.hashCode(this.blkHashVal);
return hashVal;
}
public boolean subSet(mddNode other) {
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
if(other.nodeMap[blkIter] == null && this.nodeMap[blkIter] != null)
return false;
if(this.nodeMap[blkIter] == null)
continue;
if(this.nodeMap[blkIter].length > other.nodeMap[blkIter].length)
return false;
for(int arrayIter = 0; arrayIter < this.nodeMap[blkIter].length; arrayIter++) {
mddNode thisSucc = this.getSucc(blkIter, arrayIter);
mddNode otherSucc = other.getSucc(blkIter, arrayIter);
if(thisSucc != null && otherSucc == null)
return false;
if(thisSucc != otherSucc)
return false;
}
}
return true;
}
public int[] next(int mddHeight) {
if(maxArrayBound == -1) {
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++)
if(this.nodeMap[blkIter] != null && this.nodeMap[blkIter].length > maxArrayBound)
maxArrayBound = this.nodeMap[blkIter].length;
}
for(int arrayIter = 0; arrayIter < maxArrayBound; arrayIter++) {
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
mddNode thisSucc = this.getSucc(blkIter, arrayIter);
if(thisSucc == null)
continue;
if(this.level == mddHeight-1) {
int stateIdx = (arrayIter << mddNode.arrayIdxoffset) | blkIter;
int[] result = new int[mddHeight];
result[this.level] = stateIdx;
return result;
}
int[] tmp = thisSucc.next(mddHeight);
if(tmp == null)
continue;
int stateIdx = (arrayIter << mddNode.arrayIdxoffset) | blkIter;
tmp[this.level] = stateIdx;
return tmp;
}
}
return null;
}
public int[] next(int mddHeight, int[] curIdxArray) {
int curIdx = curIdxArray[this.level];
// Find the largest array bound.
if(maxArrayBound == -1) {
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++)
if(this.nodeMap[blkIter] != null && this.nodeMap[blkIter].length > maxArrayBound)
maxArrayBound = this.nodeMap[blkIter].length;
}
if(this.level == mddHeight-1) {
int newIdx = curIdx + 1;
int newBlkIdx = newIdx & mddNode.blockIdxMask;
int newArrayIdx = newIdx >> mddNode.arrayIdxoffset;
for(int arrayIter = newArrayIdx; arrayIter < maxArrayBound; arrayIter++) {
int startingBlkIdx = (arrayIter > newArrayIdx) ? 0 : newBlkIdx;
for(int blkIter = startingBlkIdx; blkIter < mddNode.numBlocks; blkIter++) {
// if(this.nodeMap[blkIter] == null)
// continue;
mddNode thisSucc = this.getSucc(blkIter, arrayIter);
if(thisSucc == null)
continue;
int stateIdx = (arrayIter << mddNode.arrayIdxoffset) | blkIter;
int[] result = new int[mddHeight];
result[this.level] = stateIdx;
return result;
}
}
return null;
}
int curBlkIdx = curIdx & mddNode.blockIdxMask;
int curArrayIdx = curIdx >> mddNode.arrayIdxoffset;
mddNode thisSucc = this.getSucc(curBlkIdx, curArrayIdx);
int[] tmp = thisSucc.next(mddHeight, curIdxArray);
if(tmp != null) {
tmp[this.level] = curIdx;
return tmp;
}
int newIdx = curIdx + 1;
int newBlkIdx = newIdx & mddNode.blockIdxMask;
int newArrayIdx = newIdx >> mddNode.arrayIdxoffset;
for(int arrayIter = newArrayIdx; arrayIter < maxArrayBound; arrayIter++) {
int startingBlkIdx = (arrayIter > newArrayIdx) ? 0 : newBlkIdx;
for(int blkIter = startingBlkIdx; blkIter < mddNode.numBlocks; blkIter++) {
// if(this.nodeMap[blkIter] == null)
// continue;
thisSucc = this.getSucc(blkIter, arrayIter);
if(thisSucc == null)
continue;
int stateIdx = (arrayIter << mddNode.arrayIdxoffset) | blkIter;
int[] result = thisSucc.next(mddHeight);
result[this.level] = stateIdx;
return result;
}
}
return null;
}
public void increaseRefCnt() {
refCount++;
}
public void decreaseRefCnt() {
if(refCount == 1) {
System.out.println("Cannot decrease the ref count of 1");
System.exit(0);
}
refCount--;
}
public int getRefCount() {
return refCount;
}
public int getSuccSize() {
return nodeMap.length;
}
public double pathCount(HashSet<mddNode> uniqueNodes) {
uniqueNodes.add(this);
double paths = 0.0;
if(this == Mdd.terminal)
return paths;
for(int blkIter = 0; blkIter != mddNode.numBlocks; blkIter++) {
if(this.nodeMap[blkIter] == null)
continue;
for(int arrayIter = 0; arrayIter < this.nodeMap[blkIter].length; arrayIter++) {
if(this.nodeMap[blkIter][arrayIter] == null)
continue;
if(this.nodeMap[blkIter][arrayIter] == Mdd.terminal)
paths += 1;
else
paths += nodeMap[blkIter][arrayIter].pathCount(uniqueNodes);
}
}
return paths;
}
public void print() {
if(nodeMap.length == 0)
return;
for(int blkIter = 0; blkIter < mddNode.numBlocks; blkIter++) {
if(this.nodeMap[blkIter] == null)
continue;
for(int arrayIter = 0; arrayIter < nodeMap[blkIter].length; arrayIter++) {
if(this.nodeMap[blkIter][arrayIter] == null)
continue;
System.out.println(this + " level = " + level + ", " + (blkIter + (arrayIter << mddNode.arrayIdxoffset)) + " -> " + nodeMap[blkIter][arrayIter] + " refCount = " + nodeMap[blkIter][arrayIter].refCount);
nodeMap[blkIter][arrayIter].print();
}
}
}
}

View file

@ -0,0 +1,174 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.MDD;
import java.util.*;
import edu.utah.ece.async.lema.verification.platu.stategraph.*;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class mdtNode {
//private Stack<State> localStateSet;
int level;
private HashMap<State, mdtNode> nodeMap;
mdtNode() {
//localStateSet = new Stack<State>();
this.level = 0;
this.nodeMap = new HashMap<State, mdtNode>();
}
public boolean push(State[] curIdxArray, int level) {
State curIdx = curIdxArray[this.level];
mdtNode nextNode = this.nodeMap.get(curIdx);
if(nextNode != null) {
if(this.level == curIdxArray.length-1) {
return false;
}
nextNode.push(curIdxArray, level+1);
return true;
}
if(this.level == curIdxArray.length-1)
this.nodeMap.put(curIdx, MDT.terminal);
else {
nextNode = new mdtNode();
nextNode.level = this.level + 1;
nextNode.push(curIdxArray, level+1);
this.nodeMap.put(curIdx, nextNode);
}
//this.localStateSet.push(curIdx);
return true;
}
public State[] pop(State[] prjState) {
//State[] prjState = null;
//State curLocalState = localStateSet.peek();
State curLocalState = null;
Set<State> keySet = this.nodeMap.keySet();
for(State st : keySet) {
curLocalState = st;
break;
}
prjState[this.level] = curLocalState;
mdtNode nextNode = this.nodeMap.get(curLocalState);
if(nextNode == MDT.terminal) {
prjState[level] = curLocalState;
this.nodeMap.remove(curLocalState);
}
else {
prjState = nextNode.pop(prjState);
if(nextNode.empty()==true) {
this.nodeMap.remove(curLocalState);
}
}
return prjState;
}
public Stack<State[]> popList(State[] prjState) {
//State[] prjState = null;
//State curLocalState = localStateSet.peek();
State curLocalState = null;
Set<State> keySet = this.nodeMap.keySet();
Stack<State[]> stateArrayList = null;
if(this.level == prjState.length-1) {
Stack<State[]> prjStateList = new Stack<State[]>();
for(State st : keySet) {
State[] stateArray = prjState.clone();
stateArray[this.level] = st;
prjStateList.push(stateArray);
}
this.nodeMap = null;
return prjStateList;
}
for(State st : keySet) {
curLocalState = st;
break;
}
prjState[this.level] = curLocalState;
mdtNode nextNode = this.nodeMap.get(curLocalState);
if(nextNode == MDT.terminal) {
//Stack<State[]> results = new Stack<State[]>();
//prjState = new State[level+1];
//prjState[level] = curLocalState;
//this.localStateSet.pop();
this.nodeMap.remove(curLocalState);
}
else {
stateArrayList = nextNode.popList(prjState);
//prjState[level] = curLocalState;
if(nextNode.empty()==true) {
//this.localStateSet.pop();
this.nodeMap.remove(curLocalState);
}
}
return stateArrayList;
}
// public State[] peek(int level) {
// State[] prjState = null;
// State curLocalState = this.localStateSet.peek();
// mdtNode nextNode = this.nodeMap.get(curLocalState);
// if(nextNode == MDT.terminal) {
// prjState = new State[level+1];
// }
// else {
// prjState = nextNode.peek(level+1);
// }
//
// prjState[level] = curLocalState;
// return prjState;
// }
public boolean contains(State[] curIdxArray, int level) {
// if(this.localStateSet.search(curIdxArray[level])==-1)
// return false;
if(this.nodeMap.get(curIdxArray[level]) == null)
return false;
if(level == curIdxArray.length-1)
return true;
mdtNode nextNode = this.nodeMap.get(curIdxArray[level]);
return nextNode.contains(curIdxArray, level+1);
}
public boolean empty() {
return (this.nodeMap==null || this.nodeMap.size() == 0);
}
public int nodeCnt() {
if(this.nodeMap == null)
return 1;
int totalChildren = 0;
Set<State> keySet = this.nodeMap.keySet();
for(State st : keySet)
totalChildren += this.nodeMap.get(st).nodeCnt();
return totalChildren + 1;
}
}

View file

@ -0,0 +1,223 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.TimingAnalysis;
import java.util.*;
import edu.utah.ece.async.lema.verification.platu.common.Pair;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class DBM {
private int[][] matrix;
private int hashVal;
private int refCount;
DBM(int dim) {
matrix = new int[dim][dim];
for(int x = 0; x < dim; x++)
for(int y = 0; y < dim; y++)
matrix[x][y] = 0;
this.hashVal = 0;
this.refCount = 0;
}
public DBM(DBM other) {
this.hashVal = other.hashVal;
int dim = other.dimension();
this.matrix = new int[dim][dim];
for(int x = 0; x < dim; x++)
for(int y = 0; y < dim; y++)
this.matrix[x][y] = other.matrix[x][y];
this.refCount = 0;
}
/**
*
* @return
*/
final public int dimension() {
return this.matrix.length;
}
@Override
public Object clone() {
return new DBM(this);
}
public void assign(int x, int y, int val) {
matrix[x][y] = val;
this.hashVal = 0;
}
public int value(int x, int y) {
return matrix[x][y];
}
public void canonicalize() {
int dim = matrix.length;
for(int x = 0; x < dim; x++)
for(int y = 0; y < dim; y++) {
if(x==y) continue;
for(int i = 0; i < dim; i++) {
if(i==x || i==y) continue;
if(matrix[x][i]==edu.utah.ece.async.lema.verification.platu.common.Common.INFINITY || matrix[i][y]==edu.utah.ece.async.lema.verification.platu.common.Common.INFINITY)
continue;
if(matrix[x][y] > matrix[x][i] + matrix[i][y])
matrix[x][y] = matrix[x][i] + matrix[i][y];
}
}
hashVal = 0;
}
public void restrict(int x, int value) {
this.matrix[x][0] = -value;
this.hashVal = 0;
}
public DBM merge(DBM other) {
int dim = this.dimension();
DBM newDbm = new DBM(dim);
for(int i = 0; i < dim; i++)
for(int j = 0; j < dim; j++) {
int maxVal_ij = this.value(i, j) > other.value(i, j) ? this.value(i, j) : other.value(i, j);
int maxVal_ji = this.value(j, i) > other.value(j, i) ? this.value(j, i) : other.value(j, i);
newDbm.assign(i, j, maxVal_ij);
newDbm.assign(j, i, maxVal_ji);
}
return newDbm;
}
/*
* Check if this DBM is a subset of the other DBM.
*/
public boolean subset(DBM other) {
int dim = this.dimension();
for(int x = 0; x < dim; x++)
for(int y = 0; y < dim; y++) {
if(this.matrix[x][y] > other.matrix[x][y])
return false;
}
return true;
}
/*
* Return a DBM with all redundant edges removed.
* @see 'Timed Automata: Semantics, Algorithms and Tools
*/
public HashMap<Pair<Integer,Integer>, Integer> getMinConstr() {
int dim = matrix.length;
HashMap<Pair<Integer,Integer>, Integer> constrSet = new HashMap<Pair<Integer,Integer>, Integer>();
for(int x = 0; x < dim; x++)
for(int y = 0; y < dim; y++) {
if(x==y) continue;
for(int i = 0; i < dim; i++) {
if(i==x || i==y) continue;
if(matrix[x][i]==edu.utah.ece.async.lema.verification.platu.common.Common.INFINITY || matrix[i][y]==edu.utah.ece.async.lema.verification.platu.common.Common.INFINITY)
continue;
if(matrix[x][i] + matrix[i][y] > matrix[x][y])
constrSet.put(new Pair<Integer,Integer>(x,y), this.matrix[x][y]);
}
}
return constrSet;
}
@Override
final public int hashCode() {
if(this.hashVal != 0)
return hashVal;
int dim = matrix.length;
int[] tmp_hash = new int[dim];
for(int i = 0; i < dim; i++)
tmp_hash[i] = Integer.rotateLeft(Arrays.hashCode(this.matrix[i]), i);
return Arrays.hashCode(tmp_hash);
}
/**
*
* @param o
* @return
*/
@Override
final public boolean equals(Object other) {
DBM otherDbm = (DBM)other;
if (this.matrix == otherDbm.matrix)
return true;
int dim = this.dimension();
if(this.dimension() != otherDbm.dimension())
return false;
for(int x = 0; x < dim; x++)
for(int y = 0; y < dim; y++)
if(this.matrix[x][y] != otherDbm.matrix[x][y])
return false;
return true;
}
@Override
public String toString() {
int dim = this.dimension();
String strOut = new String();
for(int x = 0; x < dim; x++) {
for(int y = 0; y < dim; y++) {
if(this.matrix[x][y] == edu.utah.ece.async.lema.verification.platu.common.Common.INFINITY)
strOut += "\tINF";
else
strOut += "\t" + this.matrix[x][y];
}
strOut += "\n";
}
return strOut + "\n";
}
public int[] signature() {
int dim = this.dimension();
int[] result = new int[this.dimension() * this.dimension()];
for(int i = 0; i < this.dimension(); i++)
for(int j = 0; j < this.dimension(); j++) {
int pos = i * dim + j;
result[pos] = this.matrix[i][j];
}
return result;
}
public void incRefCnt() {
this.refCount++;
}
public int decrRefCnt() {
this.refCount--;
return this.refCount;
}
}

View file

@ -0,0 +1,257 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.TimingAnalysis;
import java.util.*;
import edu.utah.ece.async.lema.verification.lpn.Transition;
import edu.utah.ece.async.lema.verification.platu.platuLpn.*;
/**
* This class implements the POSET algorithm in C Myers's book, section 7.5.
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Poset {
public static final int INFINITY = edu.utah.ece.async.lema.verification.platu.common.Common.INFINITY;
protected HashMap<Transition, HashSet<Transition>> causalityFwd;
protected HashMap<Transition, Transition> causalityBwd;
protected DualHashMap<Transition, Integer> tranIdxMap;
protected DBM dbm;
public Poset() {
causalityFwd = null;
causalityBwd = null;
tranIdxMap = null;
dbm = null;
}
public void initialize(Transition firedTran, LpnTranList[] nextEnabledArray) {
causalityFwd = new HashMap<Transition, HashSet<Transition>>();
causalityBwd = new HashMap<Transition, Transition>();
HashSet<Transition> enabledSet = new HashSet<Transition>();
for(int i = 0; i < nextEnabledArray.length; i++)
if(nextEnabledArray[i] != null)
for(Transition tran : nextEnabledArray[i]) {
enabledSet.add(tran);
this.causalityBwd.put(tran, firedTran);
}
this.causalityFwd.put(firedTran, enabledSet);
this.tranIdxMap = new DualHashMap<Transition, Integer>();
this.tranIdxMap.insert(firedTran, this.tranIdxMap.size());
this.dbm = new DBM(1);
}
public Poset update(Transition firedTran, LpnTranList[] curEnabledArray, LpnTranList[] nextEnabledArray) {
Poset newPoset = new Poset();
newPoset.tranIdxMap = new DualHashMap<Transition, Integer>();
for(int i = 0; i < this.tranIdxMap.size(); i++) {
Transition tran = this.tranIdxMap.getKey(i);
newPoset.tranIdxMap.insert(tran, i);
}
newPoset.causalityBwd = (HashMap<Transition, Transition>) this.causalityBwd.clone();
newPoset.causalityFwd = new HashMap<Transition, HashSet<Transition>>();
DBM dbmCopy = new DBM(this.dbm.dimension() + 1);
for(int i = 0; i < this.tranIdxMap.size(); i++) {
Transition curTran = newPoset.tranIdxMap.getKey(i);
HashSet<Transition> curEnabledSet = this.causalityFwd.get(curTran);
if(curEnabledSet==null) {
System.out.println("*** Transition does not exist in causalityFwd");
return null;
}
newPoset.causalityFwd.put(curTran, (HashSet<Transition>)curEnabledSet.clone());
for(int j = 0; j < this.tranIdxMap.size(); j++) {
dbmCopy.assign(i, j, this.dbm.value(i, j));
}
}
/*
* Adjust newPoset with firedTran
*/
// Find the new enabled transition due to firedTran.
HashSet<Transition> curEnabledSet = new HashSet<Transition>();
HashSet<Transition> newEnabledSet = new HashSet<Transition>();
for(int i = 0; i < curEnabledArray.length; i++) {
if(curEnabledArray[i] != null)
for(Transition tran : curEnabledArray[i])
curEnabledSet.add(tran);
}
for(int i = 0; i < nextEnabledArray.length; i++) {
if(nextEnabledArray[i] != null)
for(Transition tran : nextEnabledArray[i])
if(curEnabledSet.contains(tran) == false) {
newEnabledSet.add(tran);
newPoset.causalityBwd.put(tran, firedTran);
}
}
newPoset.causalityFwd.put(firedTran, newEnabledSet);
newPoset.tranIdxMap.insert(firedTran, newPoset.tranIdxMap.size());
// Add the firedTran into newPoset, and set its time separations with other transitions in newPoset.
int firedTranIdx = newPoset.tranIdxMap.getValue(firedTran);
for(int i = 0; i < newPoset.tranIdxMap.size(); i++) {
Transition prevTran = newPoset.tranIdxMap.getKey(i);
if(prevTran == firedTran) continue;
HashSet prevEnabledSet = newPoset.causalityFwd.get(prevTran);
if(prevEnabledSet.contains(firedTran) == true) {
// TODO: Get upper and lower bounds for our LPN?
//dbmCopy.assign(firedTranIdx, i, firedTran.getDelayUB());
//dbmCopy.assign(i, firedTranIdx, -firedTran.getDelayLB());
}
else {
dbmCopy.assign(i, firedTranIdx, INFINITY);
dbmCopy.assign(firedTranIdx, i, INFINITY);
}
}
dbmCopy.canonicalize();
/*
* Projecting the useless transitions from newPoset.
*/
Transition firedEnabling = newPoset.causalityBwd.get(firedTran);
HashSet<Transition> firedSiblings = newPoset.causalityFwd.get(firedEnabling);
firedSiblings.remove(firedTran);
// System.out.println("tranIdxMap");
// for(int i = 0; i < newPoset.tranIdxMap.size(); i++) {
// LPNTran thisTran = newPoset.tranIdxMap.getKey(i);
// System.out.print(thisTran.getFullLabel()+", ");
// }
// System.out.println("");
HashSet<Transition> uselessTranSet = new HashSet<Transition>();
for(int i = 0; i < newPoset.tranIdxMap.size(); i++) {
Transition thisTran = newPoset.tranIdxMap.getKey(i);
// HashSet<LPNTran> thisEnabledSet = newPoset.causalityFwd.get(thisTran);
// boolean useless = true;
// System.out.print(thisTran.getFullLabel() + " : ");
// for(LPNTran enabled : thisEnabledSet) {
//System.out.print(thisTran.getFullLabel() + ", ");
//if(newPoset.tranIdxMap.getValue(enabled) == null) {
if(newPoset.causalityFwd.get(thisTran).size() == 0) {
// useless = false;
// break;
// }
//}
//System.out.println("\n");
//if(useless==true)
uselessTranSet.add(thisTran);
}
}
for(Transition uselessTran : uselessTranSet) {
HashSet<Transition> uselessTranEnabled = newPoset.causalityFwd.get(uselessTran);
for(Transition tran : uselessTranEnabled) {
newPoset.causalityBwd.remove(tran);
}
newPoset.causalityFwd.remove(uselessTran);
}
DualHashMap<Transition, Integer> newTranIdxMap = new DualHashMap<Transition, Integer>();
for(int i = 0; i < newPoset.tranIdxMap.size(); i++) {
Transition tran_i = newPoset.tranIdxMap.getKey(i);
if(uselessTranSet.contains(tran_i) == false) {
newTranIdxMap.insert(tran_i, newTranIdxMap.size());
}
}
DualHashMap<Transition, Integer> oldTranIdxMap = newPoset.tranIdxMap;
newPoset.tranIdxMap = newTranIdxMap;
/*
* Adjust dbmCopy by removing the entries w.r.t newTranIdxMap
*/
newPoset.dbm = new DBM(newPoset.tranIdxMap.size());
for(int new_i = 0; new_i < newPoset.tranIdxMap.size(); new_i++) {
Transition new_tran_i = newPoset.tranIdxMap.getKey(new_i);
int old_i = oldTranIdxMap.getValue(new_tran_i);
for(int new_j = 0; new_j < newPoset.tranIdxMap.size(); new_j++) {
Transition new_tran_j = newPoset.tranIdxMap.getKey(new_j);
int old_j = oldTranIdxMap.getValue(new_tran_j);
newPoset.dbm.assign(new_i, new_j, dbmCopy.value(old_i, old_j));
newPoset.dbm.assign(new_j, new_i, dbmCopy.value(old_j, old_i));
}
}
return newPoset;
}
/*
* Return the time separation between two transitions as defined in this Poset.
*/
public int getTimeSep(Transition tran_i, Transition tran_j) {
Transition enablingTran_i = this.causalityBwd.get(tran_i);
Transition enablingTran_j = this.causalityBwd.get(tran_j);
int i = this.tranIdxMap.getValue(enablingTran_i);
int j = this.tranIdxMap.getValue(enablingTran_j);
return this.dbm.value(i, j);
}
@Override
public int hashCode() {
return Integer.rotateLeft(this.tranIdxMap.hashCode(), 11) ^ Integer.rotateLeft(this.dbm.hashCode(), 7);
}
@Override
public boolean equals(Object other) {
Poset otherPoset = (Poset)other;
if(this.tranIdxMap.equals(otherPoset.tranIdxMap)==false)
//if(this.enabledSet != otherZone.enabledSet)
return false;
// System.out.println("this zone : " + this.dbm);
// System.out.println("\nother zone : " + otherZone.dbm + "\n =================================");
if(this.dbm.equals(otherPoset.dbm)==false)
//if(this.dbm != otherZone.dbm)
return false;
// if(this.timeSep == null && otherZone.timeSep == null)
// return true;
//
// if((this.timeSep == null && otherZone.timeSep != null) || (this.timeSep != null && otherZone.timeSep == null))
// return false;
//
// if(this.timeSep.equals(otherZone.timeSep) == false)
// return false;
return true;
}
@Override
public String toString() {
String ret = new String();
for(int i = 0; i < this.tranIdxMap.size(); i++) {
ret += "\t" + this.tranIdxMap.getKey(i).getFullLabel();
}
String timeSepConstraints = new String();
return ret + "\n\n" + this.dbm.toString() + timeSepConstraints +"\n";
}
}

View file

@ -0,0 +1,69 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.TimingAnalysis;
import java.util.Arrays;
import edu.utah.ece.async.lema.verification.platu.TimingAnalysis.Zone1;
import edu.utah.ece.async.lema.verification.platu.stategraph.*;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class PrjStateZone {
State[] stateArray;
Zone1 zone;
public PrjStateZone(final State[] other, Zone1 zone) {
this.stateArray = other;
this.zone = zone;
}
@Override
public boolean equals(final Object other) {
PrjStateZone otherSt = (PrjStateZone)other;
for(int i = 0; i < this.stateArray.length; i++)
if(this.stateArray[i] != otherSt.stateArray[i])
return false;
return this.zone==otherSt.zone;
}
@Override
public int hashCode() {
return Arrays.hashCode(this.stateArray) ^ zone.hashCode();
}
/**
* @return the zone
*/
public Zone1 getZone() {
return zone;
}
public State[] getStateArray() {
return stateArray;
}
@Override
public String toString() {
return Arrays.toString(stateArray)+zone.hashCode();
}
}

View file

@ -0,0 +1,791 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.TimingAnalysis;
import java.util.*;
import edu.utah.ece.async.lema.verification.lpn.LPN;
import edu.utah.ece.async.lema.verification.lpn.Transition;
import edu.utah.ece.async.lema.verification.platu.TimingAnalysis.DBM;
import edu.utah.ece.async.lema.verification.platu.TimingAnalysis.Poset;
import edu.utah.ece.async.lema.verification.platu.TimingAnalysis.Zone1;
import edu.utah.ece.async.lema.verification.platu.logicAnalysis.Analysis;
import edu.utah.ece.async.lema.verification.platu.platuLpn.DualHashMap;
import edu.utah.ece.async.lema.verification.platu.platuLpn.LpnTranList;
import edu.utah.ece.async.lema.verification.platu.project.PrjState;
import edu.utah.ece.async.lema.verification.platu.stategraph.State;
import edu.utah.ece.async.lema.verification.platu.stategraph.StateGraph;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class TimingAnalysis {
/*
* Data member section
*/
HashMap[] timingStateCache;
/*
* Member function section
*/
public TimingAnalysis(final StateGraph[] SgArray) {
int ArraySize = SgArray.length;
timingStateCache = new HashMap[ArraySize];
long start = System.currentTimeMillis();
// Initialize the project state
HashMap<String, Integer> varValMap = new HashMap<String, Integer>();
State[] initStateArray = new State[ArraySize];
ArrayList<LinkedList<Transition>> enabledList = new ArrayList<LinkedList<Transition>>(
1);
for (int index = 0; index < ArraySize; index++) {
LPN curLpn = SgArray[index].getLpn();
StateGraph curSg = SgArray[index];
// TODO: (Check) check if curSg is correct
initStateArray[index] = curSg.genInitialState();
int[] curStateVector = initStateArray[index].getVariableVector();
HashSet<String> outVars = (HashSet<String>) curLpn.getAllOutputs().keySet();
DualHashMap<String, Integer> VarIndexMap = curLpn.getVarIndexMap();
for (String var : outVars) {
varValMap.put(var, curStateVector[VarIndexMap.getValue(var)]);
}
}
// Adjust the value of the input variables in LPN in the initial state.
for (int index = 0; index < ArraySize; index++) {
StateGraph curLpn = SgArray[index];
initStateArray[index].update(curLpn,varValMap, curLpn.getLpn().getVarIndexMap());
initStateArray[index] = curLpn.addState(initStateArray[index]);
enabledList.add(index, curLpn.getEnabled(initStateArray[index]));
}
if (Analysis.deadLock(SgArray, initStateArray) == true) {
System.err
.println("Verification failed: deadlock in the initial state.");
return;
}
// Add the initial project state into the prjStateSet, and invoke
// findsg_recursive().
HashSet<PrjState> stateTrace = new HashSet<PrjState>(1);
PrjState curPrjState = new PrjState(initStateArray);
stateTrace.add(curPrjState);
LinkedList<Transition> traceCex = new LinkedList<Transition>();
/*
* Timing analysis by DFS
*/
//this.search_dfs(SgArray, initStateArray);
TimingAnalysis.search_dfs_abstraction(SgArray, initStateArray);
// this.search_dfs_split_zone(SgArray, initStateArray);
while (traceCex.size() > 0) {
Transition lpnTran = traceCex.removeFirst();
System.out.println(lpnTran.getLpn().getLabel() + " : "
+ lpnTran.getLabel());
}
System.out.println("Modules' local states: ");
for (int i = 0; i < ArraySize; i++) {
System.out.println("module " + SgArray[i].getLpn().getLabel() + ": "
+ SgArray[i].reachSize());
}
long elapsedTimeMillis = System.currentTimeMillis() - start;
float elapsedTimeSec = elapsedTimeMillis / 1000F;
System.out.println("---> total runtime: " + elapsedTimeSec + " sec\n");// </editor-fold>
}
@SuppressWarnings("unused")
private static void search_dfs(StateGraph[] lpnList, State[] initStateArray) {
System.out.println("---> Calling TimingAnalysis.search_dfs");
//int zoneType = 0;
int arraySize = lpnList.length;
int max_stack_depth = 0;
long peakTotalMem = 0;
long peakUsedMem = 0;
boolean failure = false;
/*
* Create objects to hold state space information
*/
HashMap<PrjState, HashSet<DBM>> prjStateZoneSet = new HashMap<PrjState, HashSet<DBM>>();
// /*
// * Compute the set of input transitions for each module
// */
// HashSet[] inputTranSetArray = new HashSet[arraySize];
// for(int i = 0; i<arraySize; i++) {
// LPN curLpn = lpnList[i];
// HashSet<LPNTran> curInputTranSet = new HashSet<LPNTran>();
// HashSet<String> inputVarSet = curLpn.getInputs();
// for(int other_i = 0; other_i <arraySize; other_i++) {
// if(i == other_i) continue;
// LPNTranSet otherTranSet = lpnList[other_i].getTransitions();
// for(LPNTran other_tran : otherTranSet) {
// HashSet<String> assignedVarSet = other_tran.getAssignedVar();
// for(String assignedVar : assignedVarSet)
// if(inputVarSet.contains(assignedVar)==true) {
// curInputTranSet.add(other_tran);
// break;
// }
// }
// }
// inputTranSetArray[i] = curInputTranSet;
// }
//
// for(int i = 0; i<arraySize; i++) {
// for(LPNTran tran : (HashSet<LPNTran>)inputTranSetArray[i]) {
// System.out.print(tran.getFullLabel() + " ");
// }
// System.out.println("---------------------");
// }
/*
* Compute the untimed enabled transition arrays in the initial state
*/
LpnTranList[] initEnabledArray = new LpnTranList[arraySize];
ArrayList<LinkedList<Transition>> enabledArrayList = new ArrayList<LinkedList<Transition>>();
for (int i = 0; i < arraySize; i++) {
LpnTranList tmp = lpnList[i].getEnabled(initStateArray[i]);
initEnabledArray[i] = tmp;
enabledArrayList.add(i, tmp);
}
/*
* Compute the initial zone, project the zone to each module, and
* enlarge the zone corresponding to the zone projection.
*/
Zone1 initZone = new Zone1();
initZone.initialize(initEnabledArray);
/*
* Compute the timed enabled transitions in the initial state
*/
LpnTranList initTimedEnabled = new LpnTranList();
for (int i = 0; i < arraySize; i++) {
for (Transition tran : initEnabledArray[i])
if (initZone.checkTiming(tran) == true)
initTimedEnabled.addLast(tran);
}
if (initTimedEnabled.size() == 0) {
System.err
.println("---> ERROR: Verification failed: deadlock in the initial state.");
failure = true;
return;
}
/*
* Initializing the stacks needed for search.
*/
Stack<State[]> stateStack = new Stack<State[]>();
Stack<Zone1> zone1Stack = new Stack<Zone1>();
Stack<Poset> posetStack = new Stack<Poset>();
Stack<LpnTranList> lpnTranStack = new Stack<LpnTranList>();
stateStack.push(initStateArray);
zone1Stack.push(initZone);
posetStack.push(null);
lpnTranStack.push(initTimedEnabled);
PrjState initPrjState = new PrjState(initStateArray);
HashSet<DBM> initStateZoneSet = prjStateZoneSet.get(initPrjState);
if (initStateZoneSet == null) {
initStateZoneSet = new HashSet<DBM>();
initStateZoneSet.add(initZone.getDbm());
prjStateZoneSet.put(initPrjState, initStateZoneSet);
} else
initStateZoneSet.add(initZone.getDbm());
int tranFiringCnt = 0;
int iterations = 0;
/*
* Main search loop.
*/
main_while_loop: while (failure == false && stateStack.empty() == false) {
iterations++;
long curTotalMem = Runtime.getRuntime().totalMemory();
long curUsedMem = Runtime.getRuntime().totalMemory()
- Runtime.getRuntime().freeMemory();
if (curTotalMem > peakTotalMem)
peakTotalMem = curTotalMem;
if (curUsedMem > peakUsedMem)
peakUsedMem = curUsedMem;
// if(iterations == 200) System.exit(0);
if (iterations % 2000 == 0) {
System.out.println("---> #iteration " + iterations
+ "> # LPN transition firings: " + tranFiringCnt
+ ", # of zones: " + Zone1.uniqueCache.size()
+ ", max_stack_depth: " + max_stack_depth
+ " used memory: " + (float) curUsedMem / 1000000
+ " free memory: "
+ (float) Runtime.getRuntime().freeMemory() / 1000000);
}
if (stateStack.size() > max_stack_depth) {
max_stack_depth = stateStack.size();
}
State[] curStateArray = stateStack.peek();
Zone1 curZone = zone1Stack.peek();
Poset curPoset = posetStack.peek();
LpnTranList curTimedEnabled = lpnTranStack.peek();
if (curTimedEnabled.size() == 0) {
stateStack.pop();
zone1Stack.pop();
posetStack.pop();
lpnTranStack.pop();
continue main_while_loop;
}
Transition firedTran = curTimedEnabled.removeLast();
// System.out.println("firedTran " + firedTran.getFullLabel());
// TODO: fire has been moved to StateGraph.
State[] nextStateArray = null;//firedTran.fire(lpnList, curStateArray);
tranFiringCnt++;
LpnTranList[] curEnabledArray = new LpnTranList[arraySize];
LpnTranList[] nextEnabledArray = new LpnTranList[arraySize];
for (int i = 0; i < arraySize; i++) {
StateGraph lpn_tmp = lpnList[i];
LpnTranList enabledList = null;
enabledList = lpn_tmp.getEnabled(curStateArray[i]);
curEnabledArray[i] = enabledList;
// TODO: have to cut below because NULL
//enabledList = lpn_tmp.getEnabled(nextStateArray[i]);
//nextEnabledArray[i] = enabledList.clone();
}
// System.out.println(curZone);
// System.out.println("\nfiredTran = " + firedTran.getFullLabel() +
// "\n");
Poset nextPoset = null;
if (curPoset == null) {
nextPoset = new Poset();
nextPoset.initialize(firedTran, nextEnabledArray);
} else {
nextPoset = curPoset.update(firedTran, curEnabledArray,
nextEnabledArray);
}
// System.out.println(nextPoset);
Zone1 nextZone = curZone.update(firedTran, nextEnabledArray);
// nextZone.enlarge(nextEnabledArray, inputTranSetArray);
// Zone1 pZone = new Zone1(nextPoset, nextEnabledArray);
// System.out.println(nextZone +
// "\n---------------------------------\n");// + pZone +
// "\n========================================\n");
// /*
// * Check if nextZone already exists in the cache. If so, get the
// existing copy.
// */
// Zone1 newNextZone1 = Zone1.uniqueCache.get(nextZone);
// if(newNextZone1 == null) {
// Zone1.uniqueCache.put(nextZone, nextZone);
// System.out.println(nextZone + "\n " + Zone1.uniqueCache.size() +
// "\n---------------------------------\n");
// }
// else {
// nextZone = newNextZone1;
// }
/*
* Compute the timed enabled transitions w.r.t nextZone.
*/
LpnTranList nextTimedEnabled = new LpnTranList();
for (int i = 0; i < arraySize; i++) {
LpnTranList tmp = nextEnabledArray[i];
for (Transition tran : tmp) {
if (nextZone.checkTiming(tran) == true)
nextTimedEnabled.addLast(tran);
}
}
/*
* Check disabling error
*/
// TODO: disablingError was moved to StateGraph.
Transition disabledTran = null;//firedTran.disablingError(curTimedEnabled,
// nextTimedEnabled);
// TODO: dead code
/*
if (disabledTran != null) {
System.out.println("---> Disabling Error: "
+ disabledTran.getFullLabel() + " is disabled by "
+ firedTran.getFullLabel());
System.out.println("Current state:");
for (int ii = 0; ii < arraySize; ii++) {
System.out.println("module " + lpnList[ii].getLpn().getLabel());
System.out.println(curStateArray[ii]);
System.out.println("Enabled set: " + curEnabledArray[ii]);
}
System.out.println("Timed enabled transitions: "
+ curTimedEnabled);
System.out.println("======================\nNext state:");
for (int ii = 0; ii < arraySize; ii++) {
System.out.println("module " + lpnList[ii].getLpn().getLabel());
System.out.println(nextStateArray[ii]);
System.out.println("Enabled set: " + nextEnabledArray[ii]);
}
System.out.println("Timed enabled transitions: "
+ nextTimedEnabled);
System.out.println();
failure = true;
break main_while_loop;
}
*/
/*
* Check deadlock.
*/
if (nextTimedEnabled.size() == 0) {
System.out.println("---> ERROR: Verification failed: deadlock.");
for (int ii = 0; ii < arraySize; ii++) {
System.out.println("module " + lpnList[ii].getLpn().getLabel());
//System.out.println(nextStateArray[ii]);
System.out.println("Enabled set: " + nextEnabledArray[ii]);
}
System.out.println("Zone: " + nextZone);
failure = true;
continue main_while_loop;
}
/*
* Add the new timed state, and check if this is a new timed state.
* Zone subset relation is checked to reduce redundant zones.
*/
boolean isNew = false;
PrjState nxtPrjState = new PrjState(nextStateArray);
HashSet<DBM> nxtStateZoneSet = prjStateZoneSet.get(nxtPrjState);
if (nxtStateZoneSet == null) {
nxtStateZoneSet = new HashSet<DBM>();
nxtStateZoneSet.add(nextZone.getDbm());
prjStateZoneSet.put(nxtPrjState, nxtStateZoneSet);
isNew = true;
}
else {
LinkedList<DBM> subsetDBMs = new LinkedList<DBM>();
boolean isSubset = false;
for (Object old : nxtStateZoneSet) {
DBM oldDbm = (DBM) old;
if (isSubset == false && nextZone.getDbm().subset(oldDbm) == true)
isSubset = true;
else if (oldDbm.subset(nextZone.getDbm()) == true)
subsetDBMs.addLast(oldDbm);
}
if (isSubset == false) {
nxtStateZoneSet.add(nextZone.getDbm());
isNew = true;
}
for (DBM d : subsetDBMs)
nxtStateZoneSet.remove(d);
}
if (isNew == true) {
stateStack.push(nextStateArray);
zone1Stack.push(nextZone);
posetStack.push(nextPoset);
lpnTranStack.push(nextTimedEnabled);
}
}
int dbmCnt = 0;
Set<PrjState> stateSet = prjStateZoneSet.keySet();
HashSet<DBM> allDbmSet = new HashSet<DBM>();
for (PrjState curState : stateSet) {
HashSet<DBM> curDbmSet = prjStateZoneSet.get(curState);
for (DBM dbm_i : curDbmSet)
allDbmSet.add(dbm_i);
}
dbmCnt = allDbmSet.size();
int untimedStateCnt = prjStateZoneSet.size();
System.out.println("---> # of untimed states = " + untimedStateCnt
+ "\n" + "---> # of unique zones = " + Zone1.uniqueCache.size()
+ "\n" + "---> # of unique enabled arrays = "
+ Zone1.enabledArrayCache.size() + "\n"
+ "---> # of unique DBMs = " + dbmCnt + "\n");
System.out.println("SUMMARY: # LPN transition firings: "
+ tranFiringCnt + ", max_stack_depth: " + max_stack_depth);
}
private static void search_dfs_abstraction(StateGraph[] lpnList, State[] initStateArray) {
System.out.println("---> Calling timedProject.findsg_dfs");
int arraySize = lpnList.length;
int max_stack_depth = 0;
long peakTotalMem = 0;
long peakUsedMem = 0;
boolean failure = false;
boolean useMDT = false; // switch between prjStateSet and reachSet fto store states
/*
* Create objects to hold state space information
*/
HashMap<PrjState, DBM> prjStateSet = null;
mdtNode reachSet = null;
// TODO: I build both to eliminate warnings. It thinks it may be using a null variable below otherwise
// it cannot work out the correllation with useMDT.
//if(useMDT==true)
reachSet = new mdtNode();
//else
prjStateSet = new HashMap<PrjState, DBM>();
// /*
// * Compute the set of input transitions for each module
// */
// HashSet[] inputTranSetArray = new HashSet[arraySize];
// for(int i = 0; i<arraySize; i++) {
// LPN curLpn = lpnList[i];
// HashSet<LPNTran> curInputTranSet = new HashSet<LPNTran>();
// HashSet<String> inputVarSet = curLpn.getInputs();
// for(int other_i = 0; other_i <arraySize; other_i++) {
// if(i == other_i) continue;
// LPNTranSet otherTranSet = lpnList[other_i].getTransitions();
// for(LPNTran other_tran : otherTranSet) {
// HashSet<String> assignedVarSet = other_tran.getAssignedVar();
// for(String assignedVar : assignedVarSet)
// if(inputVarSet.contains(assignedVar)==true) {
// curInputTranSet.add(other_tran);
// break;
// }
// }
// }
// inputTranSetArray[i] = curInputTranSet;
// }
//
// for(int i = 0; i<arraySize; i++) {
// for(LPNTran tran : (HashSet<LPNTran>)inputTranSetArray[i]) {
// System.out.print(tran.getFullLabel() + " ");
// }
// System.out.println("---------------------");
// }
/*
* Compute the untimed enabled transition arrays in the initial state
*/
LpnTranList[] initEnabledArray = new LpnTranList[arraySize];
ArrayList<LinkedList<Transition>> enabledArrayList = new ArrayList<LinkedList<Transition>>();
for (int i = 0; i < arraySize; i++) {
LpnTranList tmp = lpnList[i].getEnabled(initStateArray[i]);
initEnabledArray[i] = tmp;
enabledArrayList.add(i, tmp);
}
/*
* Compute the initial zone, project the zone to each module, and
* enlarge the zone corresponding to the zone projection.
*/
Zone1 initZone = new Zone1();
initZone.initialize(initEnabledArray);
/*
* Compute the timed enabled transitions in the initial state
*/
LpnTranList initTimedEnabled = new LpnTranList();
for (int i = 0; i < arraySize; i++) {
for (Transition tran : initEnabledArray[i])
if (initZone.checkTiming(tran) == true)
initTimedEnabled.addLast(tran);
}
if (initTimedEnabled.size() == 0) {
System.err
.println("---> ERROR: Verification failed: deadlock in the initial state.");
failure = true;
return;
}
/*
* Initializing the stacks needed for search.
*/
Stack<State[]> stateStack = new Stack<State[]>();
Stack<Zone1> zone1Stack = new Stack<Zone1>();
Stack<Poset> posetStack = new Stack<Poset>();
Stack<LpnTranList> lpnTranStack = new Stack<LpnTranList>();
stateStack.push(initStateArray);
zone1Stack.push(initZone);
posetStack.push(null);
lpnTranStack.push(initTimedEnabled);
PrjState initPrjState = new PrjState(initStateArray);
if (useMDT==true)
reachSet.merge(initStateArray, initZone.getDbm(), 0);
else
prjStateSet.put(initPrjState, initZone.getDbm());
int tranFiringCnt = 0;
int iterations = 0;
/*
* Main search loop.
*/
main_while_loop: while (failure == false && stateStack.empty() == false) {
iterations++;
long curTotalMem = Runtime.getRuntime().totalMemory();
long curUsedMem = Runtime.getRuntime().totalMemory()
- Runtime.getRuntime().freeMemory();
if (curTotalMem > peakTotalMem)
peakTotalMem = curTotalMem;
if (curUsedMem > peakUsedMem)
peakUsedMem = curUsedMem;
// if(iterations == 200) System.exit(0);
if (iterations % 2000 == 0) {
System.out.println("---> #iteration " + iterations
+ "> # LPN transition firings: " + tranFiringCnt
+ ", # of prjStates: " + (useMDT ? reachSet.pathCount() : prjStateSet.size())
+ ", # of zones: " + Zone1.uniqueCache.size()
+ ", max_stack_depth: " + max_stack_depth
+ " used memory: " + (float) curUsedMem / 1000000
+ " free memory: "
+ (float) Runtime.getRuntime().freeMemory() / 1000000);
}
if (stateStack.size() > max_stack_depth) {
max_stack_depth = stateStack.size();
}
State[] curStateArray = stateStack.peek();
Zone1 curZone = zone1Stack.peek();
PrjState curPrjState = new PrjState(curStateArray);
DBM curExistingDbm = null;
if (useMDT==true)
curExistingDbm = reachSet.getDbm(curStateArray, 0);
else
curExistingDbm = prjStateSet.get(curPrjState);
boolean curZoneUseless = (curZone.getDbm().equals(curExistingDbm) == false && curZone.getDbm().subset(curExistingDbm) == true);
Poset curPoset = posetStack.peek();
LpnTranList curTimedEnabled = lpnTranStack.peek();
if (curTimedEnabled.size() == 0 || curZoneUseless==true) {
stateStack.pop();
zone1Stack.pop();
posetStack.pop();
lpnTranStack.pop();
continue main_while_loop;
}
Transition firedTran = curTimedEnabled.removeLast();
// for(int i = 0; i < curStateArray.length; i++)
// System.out.print(curStateArray[i] + ", ");
// System.out.println();
// System.out.println("firedTran " + firedTran.getFullLabel());
//int curIndex = firedTran.getLpn().getLpnIndex();
// TODO: fire has been moved to StateGraph.
State[] nextStateArray = null; //firedTran.fire(lpnList, curStateArray);
tranFiringCnt++;
LpnTranList[] curEnabledArray = new LpnTranList[arraySize];
LpnTranList[] nextEnabledArray = new LpnTranList[arraySize];
for (int i = 0; i < arraySize; i++) {
StateGraph lpn_tmp = lpnList[i];
LpnTranList enabledList = null;
enabledList = lpn_tmp.getEnabled(curStateArray[i]);
curEnabledArray[i] = enabledList;
// TODO: have to cut below because NULL
//enabledList = lpn_tmp.getEnabled(nextStateArray[i]);
//nextEnabledArray[i] = enabledList.clone();
}
// System.out.println(curZone);
// System.out.println("\nfiredTran = " + firedTran.getFullLabel() +
// "\n");
Poset nextPoset = null;
if (curPoset == null) {
nextPoset = new Poset();
nextPoset.initialize(firedTran, nextEnabledArray);
} else {
nextPoset = curPoset.update(firedTran, curEnabledArray,
nextEnabledArray);
}
// System.out.println(nextPoset);
Zone1 nextZone = curZone.update(firedTran, nextEnabledArray);
// nextZone.enlarge(nextEnabledArray, inputTranSetArray);
// Zone1 pZone = new Zone1(nextPoset, nextEnabledArray);
// System.out.println(nextZone +
// "\n---------------------------------\n");// + pZone +
// "\n========================================\n");
// /*
// * Check if nextZone already exists in the cache. If so, get the
// existing copy.
// */
// Zone1 newNextZone1 = Zone1.uniqueCache.get(nextZone);
// if(newNextZone1 == null) {
// Zone1.uniqueCache.put(nextZone, nextZone);
// System.out.println(nextZone + "\n " + Zone1.uniqueCache.size() +
// "\n---------------------------------\n");
// }
// else {
// nextZone = newNextZone1;
// }
/*
* Compute the timed enabled transitions w.r.t nextZone.
*/
LpnTranList nextTimedEnabled = new LpnTranList();
for (int i = 0; i < arraySize; i++) {
LpnTranList tmp = nextEnabledArray[i];
for (Transition tran : tmp) {
if (nextZone.checkTiming(tran) == true)
nextTimedEnabled.addLast(tran);
}
}
/*
* Check disabling error
*/
// TODO: disablingError was moved to StateGraph.
//Transition disabledTran = null;//firedTran.disablingError(curTimedEnabled,
// nextTimedEnabled);
// TODO: DEAD CODE
/*
if (disabledTran != null) {
System.out.println("---> Disabling Error: "
+ disabledTran.getFullLabel() + " is disabled by "
+ firedTran.getFullLabel());
System.out.println("Current state:");
for (int ii = 0; ii < arraySize; ii++) {
System.out.println("module " + lpnList[ii].getLpn().getLabel());
System.out.println(curStateArray[ii]);
System.out.println("Enabled set: " + curEnabledArray[ii]);
}
System.out.println("Timed enabled transitions: "
+ curTimedEnabled);
System.out.println("======================\nNext state:");
for (int ii = 0; ii < arraySize; ii++) {
System.out.println("module " + lpnList[ii].getLpn().getLabel());
System.out.println(nextStateArray[ii]);
System.out.println("Enabled set: " + nextEnabledArray[ii]);
}
System.out.println("Timed enabled transitions: "
+ nextTimedEnabled);
System.out.println();
failure = true;
break main_while_loop;
}
*/
/*
* Check deadlock.
*/
if (nextTimedEnabled.size() == 0) {
System.out
.println("---> ERROR: Verification failed: deadlock.");
for (int ii = 0; ii < arraySize; ii++) {
System.out.println("module " + lpnList[ii].getLpn().getLabel());
//System.out.println(nextStateArray[ii]);
System.out.println("Enabled set: " + nextEnabledArray[ii]);
}
System.out.println("Zone: " + nextZone);
failure = true;
continue main_while_loop;
}
/*
* Add the new timed state, and check if this is a new timed state.
* Zone subset relation is checked to reduce redundant zones.
*/
boolean isNew = false;
PrjState nextPrjState = new PrjState(nextStateArray);
DBM existingDBM = null;
if (useMDT==true)
existingDBM = reachSet.getDbm(nextStateArray, 0);
else
existingDBM = prjStateSet.get(nextPrjState);
if (existingDBM == null) {
if (useMDT==true)
reachSet.merge(nextStateArray, nextZone.getDbm(), 0);
else
prjStateSet.put(nextPrjState, nextZone.getDbm());
isNew = true;
}
else if (nextZone.getDbm().subset(existingDBM)==false) {
DBM newDbm = existingDBM.merge(nextZone.getDbm());
Zone1 newNextZone = new Zone1(nextZone.getEnabledSet(), newDbm);
nextZone = newNextZone;
if (useMDT==true)
reachSet.merge(nextStateArray, newDbm, 0);
else
prjStateSet.put(nextPrjState, newDbm);
isNew = true;
}
if (isNew == true) {
stateStack.push(nextStateArray);
zone1Stack.push(nextZone);
posetStack.push(nextPoset);
lpnTranStack.push(nextTimedEnabled);
}
}
System.out.println("SUMMARY:\n"
+ "# LPN transition firings: "
+ tranFiringCnt + ", # of prjStates found: " + (useMDT ? reachSet.pathCount() : prjStateSet.size()) + ", "
+ ", max_stack_depth: "
+ max_stack_depth + "\n"
+ "---> # of unique zones = "
+ Zone1.uniqueCache.size() + "\n"
+ "---> # of unique enabled arrays = "
+ Zone1.enabledArrayCache.size() + "\n"
+ "---> # of unique DBMs = " + (useMDT ? reachSet.pathCount() : prjStateSet.size()) + "\n"
+ "---> # of unique timeSeps = " + Zone1.timeSepTbl.size()
+ "\n");
}
}

View file

@ -0,0 +1,88 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.TimingAnalysis;
import edu.utah.ece.async.lema.verification.platu.TimingAnalysis.Zone1;
import edu.utah.ece.async.lema.verification.platu.stategraph.State;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class TimingState {
State state;
Zone1 zone;
int index;
public TimingState() {
state = null;
zone = null;
index = -1;
}
public TimingState(State newState, Zone1 newZone) {
state = newState;
this.zone = newZone;
index = -1;
}
public TimingState(TimingState other) {
this.state = other.state;
this.zone = other.zone;
this.index = other.index;
}
public void setIndex(int idx) {
this.index = idx;
}
public int getIndex() {
return this.index;
}
@Override
public String toString() {
return state.toString() + "\n" + zone.toString() + "\n";
}
@Override
public boolean equals(Object other) {
TimingState otherState = (TimingState)other;
if(this.state != otherState.state)
return false;
if((this.zone==null && otherState.zone!=null) || (this.zone!=null && otherState.zone==null))
return false;
if(this.zone != null && otherState.zone != null && this.zone.equals(otherState.zone)==false)
return false;
return true;
}
@Override
public int hashCode() {
if(this.zone == null)
return state.hashCode();
return state.hashCode() ^ this.zone.hashCode();
}
}

View file

@ -0,0 +1,632 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.TimingAnalysis;
import java.util.*;
import edu.utah.ece.async.lema.verification.lpn.Transition;
import edu.utah.ece.async.lema.verification.platu.platuLpn.*;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Zone1 {
public static final int INFINITY = edu.utah.ece.async.lema.verification.platu.common.Common.INFINITY;
public static HashMap<Zone1, Zone1> uniqueCache = null;
public static HashMap<DualHashMap, DualHashMap> enabledArrayCache = null;
//public static HashMap<DBM, DBM> dbmCache = null;
public static HashMap<LinkedList<Integer>, LinkedList<Integer>> timeSepTbl = null;
DualHashMap<Transition, Integer> enabledSet;
private DBM dbm;
//HashMap<LinkedList<LPNTran>, Integer> timeSep;
public Zone1() {
if(Zone1.uniqueCache==null)
Zone1.uniqueCache = new HashMap<Zone1, Zone1>();
if(Zone1.enabledArrayCache==null)
Zone1.enabledArrayCache = new HashMap<DualHashMap, DualHashMap>();
if(Zone1.timeSepTbl==null)
Zone1.timeSepTbl = new HashMap<LinkedList<Integer>, LinkedList<Integer>>();
enabledSet = null;
dbm = null;
//timeSep = null;
}
public Zone1(Object other) {
Zone1 otherZone = (Zone1)other;
enabledSet = otherZone.enabledSet;
dbm = otherZone.dbm;
//timeSep = otherZone.timeSep;
}
public Zone1(DualHashMap<Transition, Integer> newEnabledSet, DBM newDbm) {
this.enabledSet = newEnabledSet;
this.dbm = newDbm;
}
/*
* Generate a new zone from a poset.
*/
public Zone1(Poset curPoset, LpnTranList[] nextEnabledArray) {
this.enabledSet = new DualHashMap<Transition, Integer>();
int arraySize = nextEnabledArray.length;
int lpnTranCnt = 0;
for(int i = 0; i < arraySize; i++) {
for(Transition tran : nextEnabledArray[i]) {
this.enabledSet.insert(tran, lpnTranCnt+1);
lpnTranCnt++;
}
}
/*
* Caching the enabled transition set.
*/
DualHashMap<Transition, Integer> newEnabledSet = Zone1.enabledArrayCache.get(this.enabledSet);
if (newEnabledSet == null)
Zone1.enabledArrayCache.put(this.enabledSet, this.enabledSet);
else
this.enabledSet = newEnabledSet;
this.dbm = new DBM(lpnTranCnt + 1);
for (int i = 1; i <= lpnTranCnt; i++) {
Transition tran_i = this.enabledSet.getKey(i);
// TODO: Get the upper bound of our LPN delay
//this.dbm.assign(0, i, tran_i.getDelayUB());
this.dbm.assign(i, 0, 0);
for (int j = 1; j <= lpnTranCnt; j++) {
Transition tran_j = this.enabledSet.getKey(j);
if(tran_i == tran_j)
continue;
if(curPoset != null)
this.dbm.assign(i, j, curPoset.getTimeSep(tran_i, tran_j));
else
this.dbm.assign(i, j, 0);
}
}
this.dbm.canonicalize();
/*
* Zone normalization
*/
int newLpnTranCnt = this.enabledSet.size();
for(int i = 1; i <= newLpnTranCnt; i++) {
//Transition tran = this.enabledSet.getKey(i);
// TODO: Get the upper/lower bound of our LPN delay
int premax = 3;//tran.getDelayUB()==INFINITY ? tran.getDelayLB() : tran.getDelayUB();
int delta = this.dbm.value(i, 0) + premax;
if(delta >= 0)
continue;
for(int j = 0; j <= newLpnTranCnt; j++) {
if(i == j)
continue;
int new_ij = this.dbm.value(i, j) - delta;
this.dbm.assign(i, j, new_ij);
int new_ji = this.dbm.value(j, i) + delta;
this.dbm.assign(j, i, new_ji);
}
}
LinkedList<Integer> fixup = new LinkedList<Integer>();
for(int i = 1; i <= newLpnTranCnt; i++) {
//Transition tran_i = this.enabledSet.getKey(i);
// TODO: Get the upper/lower bound of our LPN delay
int premax_i = 3; //tran_i.getDelayUB()==INFINITY ? tran_i.getDelayLB() : tran_i.getDelayUB();
if(this.dbm.value(0, i) > premax_i) {
int t = premax_i;
for(int j = 1; j <= newLpnTranCnt; j++) {
//Transition tran_j = this.enabledSet.getKey(j);
// TODO: Get the upper/lower bound of our LPN delay
int premax_j = 3; //tran_j.getDelayUB()==INFINITY ? tran_j.getDelayLB() : tran_j.getDelayUB();
int min = this.dbm.value(0, j) < premax_j ? this.dbm.value(0, j) : premax_j;
int new_max = min - this.dbm.value(i, j);
if(new_max > t)
t = new_max;
}
if(t < this.dbm.value(0, i)) {
fixup.addLast(i);
this.dbm.assign(0, i, t);
}
}
}
if(fixup.size() > 0) {
for(int i = 1; i <= newLpnTranCnt; i++) {
for(Integer j : fixup) {
if(i == j)
continue;
int val_i0 = this.dbm.value(i, 0);
int val_0j = this.dbm.value(0, j);
if(val_i0 + val_0j < this.dbm.value(i, j))
this.dbm.assign(i, j, val_0j + val_0j);
}
}
}
}
@Override
public Zone1 clone() {
return null;
}
/**
* Size of key set (width of DBM including t0).
*
* @return
*/
public int size() {
return this.enabledSet.size();
}
/**
* Initialize zone. Input is a list of lists of LPNTran
*
* @param z
* @param initEnSet
*/
final public void initialize(LpnTranList[] initEnabledArray) {
this.enabledSet = new DualHashMap<Transition, Integer>();
int arraySize = initEnabledArray.length;
int lpnTranCnt = 0;
for(int i = 0; i < arraySize; i++) {
for(Transition tran : initEnabledArray[i]) {
this.enabledSet.insert(tran, lpnTranCnt+1);
lpnTranCnt++;
}
}
/*
* Caching the enabled transition set.
*/
DualHashMap<Transition, Integer> newEnabledSet = Zone1.enabledArrayCache.get(this.enabledSet);
if(newEnabledSet==null)
Zone1.enabledArrayCache.put(this.enabledSet, this.enabledSet);
else
this.enabledSet = newEnabledSet;
this.dbm = new DBM(lpnTranCnt+1);
for(int y = 1; y <= lpnTranCnt; y++) {
//Transition curTran = this.enabledSet.getKey(y);
// TODO: Get the upper/lower bound of our LPN delay
//this.dbm.assign(0, y, curTran.getDelayUB());
}
}
/**
* Call these functions. restrict(zone, fired, lowerBound);
* zone.recanonicalize(); zone.project(fired); allocate(newSet, zone);
* extend(newSet, nmnSet, zone); advanceTime(enSet, ubSet, zone);
* zone.recanonicalize();
*
* @param firedLocalTran
* @param NEXT
* @param CURRENT
* @param nextEnabledList
* @param curModuleTranSet
*/
public Zone1 update(Transition firedTran, LpnTranList[] nextEnabledArray) {
Zone1 newZone = new Zone1();
newZone.enabledSet = new DualHashMap<Transition, Integer>();
int arraySize = nextEnabledArray.length;
int nextLpnTranCnt = 0;
for(int i = 0; i < arraySize; i++) {
for(Transition tran : nextEnabledArray[i]) {
newZone.enabledSet.insert(tran, nextLpnTranCnt+1);
nextLpnTranCnt++;
}
}
/*
* Caching the enabled transition set.
*/
DualHashMap<Transition, Integer> newEnabledSet = Zone1.enabledArrayCache.get(newZone.enabledSet);
if(newEnabledSet==null)
Zone1.enabledArrayCache.put(newZone.enabledSet, newZone.enabledSet);
else
newZone.enabledSet = newEnabledSet;
/*
* Update DBM of this zone.
*/
newZone.dbm = new DBM(nextLpnTranCnt+1);
DBM curDbmCopy = new DBM(this.dbm);
/*
* Restrict zone w.r.t firedTran, and canonialize it.
*/
int new_x = this.enabledSet.getValue(firedTran);
// TODO: Get the upper/lower bound of our LPN delay
//curDbmCopy.restrict(new_x, firedTran.getDelayLB());
curDbmCopy.canonicalize();
//System.out.println("update 1 \n" + curDbmCopy);
/*
* Copy timing information of transitions enabled in both current and new states from tmp_dbm
* to newZone
*/
int curLpnTranCnt = this.enabledSet.size();
for(int x = 0; x <= curLpnTranCnt; x++) {
new_x = 0;
if(x>0) {
Transition tran_x = this.enabledSet.getKey(x);
if(newZone.enabledSet.containsKey(tran_x) == false || tran_x==firedTran)
continue;
new_x = newZone.enabledSet.getValue(tran_x);
}
for(int y = 0; y <= curLpnTranCnt; y++) {
int new_y = 0;
if(y > 0) {
Transition tran_y = this.enabledSet.getKey(y);
if(newZone.enabledSet.containsKey(tran_y)==false || tran_y==firedTran)
continue;
new_y = newZone.enabledSet.getValue(tran_y);
}
//System.out.println("x, y = " +x+", " +y + "; new_x, new_y = " + new_x +", " + new_y + ", val(x, y) = " + tmp_dbm.value(x, y));
newZone.dbm.assign(new_x, new_y, curDbmCopy.value(x, y));
}
}
//System.out.println("update 2 \n" + newZone.dbm);
/*
* For every enabled transitions in the nextState, advance its timer to DelayUB, and canonicalize.
*/
LinkedList<Transition> newTranList = new LinkedList<Transition>();
int newLpnTranCnt = newZone.enabledSet.size();
for(int y = 1; y <= newLpnTranCnt; y++) {
Transition tran_y = newZone.enabledSet.getKey(y);
if(this.enabledSet.containsKey(tran_y)==false || tran_y == firedTran) {
newTranList.addLast(tran_y);
}
}
/*
* Adjust timing constraints between the enabled transitions in the current state and
* those that are newly enabled in the next state.
*/
curLpnTranCnt = this.enabledSet.size();
for(Transition newTran : newTranList) {
int new_i = newZone.enabledSet.getValue(newTran);
for(int j = 1; j <= curLpnTranCnt; j++) {
Transition tran_j = this.enabledSet.getKey(j);
if(newZone.enabledSet.containsKey(tran_j) == false)
continue;
int new_j = newZone.enabledSet.getValue(tran_j);
int val_0j = newZone.dbm.value(0, new_j);
newZone.dbm.assign(new_i, new_j, val_0j);
int val_j0 = newZone.dbm.value(new_j, 0);
newZone.dbm.assign(new_j, new_i, val_j0);
}
}
/*
* For every enabled transitions in the nextState, advance its timer to DelayUB, and canonicalize.
*/
HashMap<Transition, Integer> newTranSet = new HashMap<Transition, Integer>();
for(int y = 1; y <= newLpnTranCnt; y++) {
Transition tran_y = newZone.enabledSet.getKey(y);
// TODO: Get the upper/lower bound of our LPN delay
//newZone.dbm.assign(0, y, tran_y.getDelayUB());
newTranSet.put(tran_y, y);
if(this.enabledSet.containsKey(tran_y)==false || tran_y == firedTran) {
newTranList.addLast(tran_y);
}
}
//System.out.println("update 3 \n" + newZone.dbm);
newZone.dbm.canonicalize();
//System.out.println("update 4 \n" + newZone.dbm);
/*
* Zone normalization
*/
for(int i = 1; i <= newLpnTranCnt; i++) {
//Transition tran = newZone.enabledSet.getKey(i);
// TODO: Get the upper/lower bound of our LPN delay
int premax = 3; //tran.getDelayUB()==INFINITY ? tran.getDelayLB() : tran.getDelayUB();
int delta = newZone.dbm.value(i, 0) + premax;
if(delta >= 0)
continue;
for(int j = 0; j <= newLpnTranCnt; j++) {
if(i == j)
continue;
int new_ij = newZone.dbm.value(i, j) - delta;
newZone.dbm.assign(i, j, new_ij);
int new_ji = newZone.dbm.value(j, i) + delta;
newZone.dbm.assign(j, i, new_ji);
}
}
LinkedList<Integer> fixup = new LinkedList<Integer>();
for(int i = 1; i <= newLpnTranCnt; i++) {
//Transition tran_i = newZone.enabledSet.getKey(i);
// TODO: Get the upper/lower bound of our LPN delay
int premax_i = 3; //tran_i.getDelayUB()==INFINITY ? tran_i.getDelayLB() : tran_i.getDelayUB();
if(newZone.dbm.value(0, i) > premax_i) {
int t = premax_i;
for(int j = 1; j <= newLpnTranCnt; j++) {
//Transition tran_j = newZone.enabledSet.getKey(j);
// TODO: Get the upper/lower bound of our LPN delay
int premax_j = 3; //tran_j.getDelayUB()==INFINITY ? tran_j.getDelayLB() : tran_j.getDelayUB();
int min = newZone.dbm.value(0, j) < premax_j ? newZone.dbm.value(0, j) : premax_j;
int new_max = min - newZone.dbm.value(i, j);
if(new_max > t)
t = new_max;
}
if(t < newZone.dbm.value(0, i)) {
fixup.addLast(i);
newZone.dbm.assign(0, i, t);
}
}
}
if(fixup.size() > 0) {
for(int i = 1; i <= newLpnTranCnt; i++) {
for(Integer j : fixup) {
if(i == j)
continue;
int val_i0 = newZone.dbm.value(i, 0);
int val_0j = newZone.dbm.value(0, j);
if(val_i0 + val_0j < newZone.dbm.value(i, j))
newZone.dbm.assign(i, j, val_0j + val_0j);
}
}
}
//System.out.println("update 5 \n" + newZone.dbm);
return newZone;
}
public Zone1[] split(LpnTranList[] enabledArray) {
int arraySize = enabledArray.length;
Zone1[] subZoneArray = new Zone1[arraySize];
//HashMap<LinkedList<Transition>, Integer> timeSepSet = new HashMap<LinkedList<Transition>, Integer>();
/*
* Create the local zones and initialize their local enabledSet.
*/
for(int curIdx = 0; curIdx < arraySize; curIdx++) {
if(enabledArray[curIdx]==null || enabledArray[curIdx].size()==0) {
subZoneArray[curIdx] = null;
continue;
}
Zone1 curSubZone = new Zone1();
curSubZone.enabledSet = new DualHashMap<Transition, Integer>();
int tranIdx = 1;
//Transition curFirstTran = enabledArray[curIdx].getFirst();
for(Transition curTran : enabledArray[curIdx])
curSubZone.enabledSet.insert(curTran, tranIdx++);
/*
* Copy the cell values for the local zones from the global zone.
*/
int localDim = curSubZone.enabledSet.size();
curSubZone.dbm = new DBM(localDim + 1);
for(int x = 0; x <= localDim; x++) {
int g_x = 0;
if(x > 0) {
Transition x_tran = curSubZone.enabledSet.getKey(x);
g_x = this.enabledSet.getValue(x_tran);
}
for(int y = 0; y <= localDim; y++) {
if(x==y)
continue;
int g_y = 0;
if(y > 0) {
Transition y_tran = curSubZone.enabledSet.getKey(y);
g_y = this.enabledSet.getValue(y_tran);
}
curSubZone.dbm.assign(x, y, this.dbm.value(g_x, g_y));
}
}
/*
* Generate the time separations between this and other modules.
*/
// for(int otherIdx = 0; otherIdx < arraySize; otherIdx++) {
// if(curIdx == otherIdx || enabledArray[otherIdx] == null || enabledArray[otherIdx].size()==0)
// continue;
//
// LPNTran otherFirstTran = enabledArray[otherIdx].getFirst();
//
// if(curSubZone.timeSep==null)
// curSubZone.timeSep = new HashMap<LinkedList<LPNTran>, Integer>();
//
// int curFirstTranIdx = this.enabledSet.getValue(curFirstTran);
// int otherFirstTranIdx = this.enabledSet.getValue(otherFirstTran);
// LinkedList<LPNTran> cur2otherPair = new LinkedList<LPNTran>();
// cur2otherPair.addFirst(curFirstTran);
// cur2otherPair.addLast(otherFirstTran);
// curSubZone.timeSep.put(cur2otherPair, this.dbm.value(otherFirstTranIdx, curFirstTranIdx));
// LinkedList<LPNTran> other2curPair = new LinkedList<LPNTran>();
// other2curPair.addFirst(otherFirstTran);
// other2curPair.addLast(curFirstTran);
// curSubZone.timeSep.put(other2curPair, this.dbm.value(curFirstTranIdx, otherFirstTranIdx));
//
// timeSepSet.put(cur2otherPair, this.dbm.value(otherFirstTranIdx, curFirstTranIdx));
// timeSepSet.put(other2curPair, this.dbm.value(curFirstTranIdx, otherFirstTranIdx));
// }
subZoneArray[curIdx] = curSubZone;
}
return subZoneArray;
}
public LinkedList<Integer> enlarge(LpnTranList[] enabledArray) {
//System.out.println(this + "\n");
int arraySize = enabledArray.length;
DBM dbmCopy = new DBM(this.dbm);
this.dbm = dbmCopy;
LinkedList<Integer> timeSepSet = new LinkedList<Integer>();
for(int i = 0; i < arraySize; i++) {
for(int j = 0; j < arraySize; j++) {
if(i == j)
continue;
//boolean first_j = true;
for(Transition tran_i : enabledArray[i]) {
int m_i = this.enabledSet.getValue(tran_i);
for(Transition tran_j : enabledArray[j]) {
int m_j = this.enabledSet.getValue(tran_j);
// if(first_j) {
// first_j = false;
// timeSepSet.addLast(this.dbm.value(m_i, m_j));
// continue;
// }
//System.out.println(tran_i.getFullLabel() + " " + tran_j.getFullLabel());
this.dbm.assign(m_i, m_j, INFINITY);
this.dbm.assign(m_j, m_i, INFINITY);
}
}
}
}
//System.out.println(this.dbm + "-----------------------");
//System.out.println(this.dbm + "\n");
this.dbm.canonicalize();
//System.out.println(this.dbm + "xxxxxxxxxxxxxxxxxxxxxxx\n");
if(timeSepSet.size() > 0) {
LinkedList<Integer> newTimeSepSet = Zone1.timeSepTbl.get(timeSepSet);
if(newTimeSepSet == null)
Zone1.timeSepTbl.put(timeSepSet, timeSepSet);
else
timeSepSet = newTimeSepSet;
}
return timeSepSet;
}
public int[] signature() {
return this.dbm.signature();
}
/**
* Set (0,t) to the upper bound of t, for all t.
*
* @param initEnSet
*/
public boolean checkTiming(Transition curTran) {
// TODO: Get the upper/lower bound of our LPN delay
int curTranDelayLB = 3; // curTran.getDelayLB();
if (curTranDelayLB == 0) {
return true;
}
int x = this.enabledSet.getValue(curTran);
Integer curTimingUB = this.dbm.value(0, x);
return curTranDelayLB <= curTimingUB;
}
/*
* Check if the this zone is a subset of the other zone.
*/
public boolean subset(Zone1 other) {
if(this.enabledSet != other.enabledSet)
return false;
return this.dbm.subset(other.dbm);
}
public DualHashMap<Transition, Integer> getEnabledSet() {
return this.enabledSet;
}
public DBM getDbm() {
return this.dbm;
}
@Override
public int hashCode() {
//if(this.timeSep==null)
return Integer.rotateLeft(this.enabledSet.hashCode(), 11) ^ Integer.rotateLeft(this.dbm.hashCode(), 7);
//return Integer.rotateLeft(this.enabledSet.hashCode(), 11) ^ Integer.rotateLeft(this.dbm.hashCode(), 7) ^ Integer.rotateLeft(this.timeSep.hashCode(), 19);
}
@Override
public boolean equals(Object other) {
Zone1 otherZone = (Zone1)other;
//if(this.enabledSet.equals(otherZone.enabledSet)==false)
if(this.enabledSet != otherZone.enabledSet)
return false;
// System.out.println("this zone : " + this.dbm);
// System.out.println("\nother zone : " + otherZone.dbm + "\n =================================");
//if(this.dbm.equals(otherZone.dbm)==false)
if(this.dbm != otherZone.dbm)
return false;
// if(this.timeSep == null && otherZone.timeSep == null)
// return true;
//
// if((this.timeSep == null && otherZone.timeSep != null) || (this.timeSep != null && otherZone.timeSep == null))
// return false;
//
// if(this.timeSep.equals(otherZone.timeSep) == false)
// return false;
return true;
}
@Override
public String toString() {
String ret = new String();
ret = "\tt0";
for(int i = 1; i <= this.enabledSet.size(); i++)
ret += "\t" + this.enabledSet.getKey(i).getFullLabel();
String timeSepConstraints = new String();
// if(this.timeSep != null) {
// Set<LinkedList<LPNTran>> tranPairs = this.timeSep.keySet();
// for(LinkedList<LPNTran> tranPair : tranPairs)
// timeSepConstraints += "(" + tranPair.getFirst().getFullLabel() + ", " + tranPair.getLast().getFullLabel() + ", " + this.timeSep.get(tranPair)+"), ";
// }
// else
// timeSepConstraints = "timeSep = null";
return ret + "\n\n" + this.dbm.toString() + timeSepConstraints +"\n";
}
}

View file

@ -0,0 +1,161 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.TimingAnalysis;
import java.util.*;
import edu.utah.ece.async.lema.verification.platu.TimingAnalysis.DBM;
import edu.utah.ece.async.lema.verification.platu.stategraph.*;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class mdtNode {
static public int totalStates = 0;
private HashMap<State, mdtNode> nodeMap;
private LinkedList<DBM> dbmSet;
public mdtNode() {
this.nodeMap = null;
this.dbmSet = null;
}
public boolean add(State[] stateArray, DBM dbm, int level) {
boolean isNew = false;
if(level == stateArray.length) {
if(this.dbmSet == null) {
this.dbmSet = new LinkedList<DBM>();
this.dbmSet.addLast(dbm);
isNew = true;
}
else {
boolean isSubDbm = false;
LinkedList<DBM> subDbms = new LinkedList<DBM>();
for(DBM oldDbm : this.dbmSet) {
if(isSubDbm==false && dbm.subset(oldDbm)==true)
isSubDbm = true;
else if (oldDbm.subset(dbm)==true)
subDbms.addLast(oldDbm);
}
for (DBM subDbm : subDbms)
this.dbmSet.remove(subDbm);
if (isSubDbm==false) {
this.dbmSet.addLast(dbm);
isNew = true;
}
else
isNew = false;
}
return isNew;
}
State curState = stateArray[level];
if(this.nodeMap == null)
this.nodeMap = new HashMap<State, mdtNode>();
mdtNode nextNode = this.nodeMap.get(curState);
if(nextNode == null) {
nextNode = new mdtNode();
nextNode.add(stateArray, dbm, level + 1);
this.nodeMap.put(curState, nextNode);
isNew = true;
}
else {
isNew = nextNode.add(stateArray, dbm, level+1);
}
return isNew;
}
public DBM merge(State[] stateArray, DBM dbm, int level) {
if(level == stateArray.length) {
if(this.dbmSet == null) {
this.dbmSet = new LinkedList<DBM>();
this.dbmSet.addLast(dbm);
totalStates++;
return dbm;
}
DBM existingDbm = this.dbmSet.removeFirst();
DBM newDbm = dbm.merge(existingDbm);
this.dbmSet.addLast(newDbm);
return newDbm;
}
State curState = stateArray[level];
if(this.nodeMap == null)
this.nodeMap = new HashMap<State, mdtNode>();
int nextLevel = level+1;
mdtNode nextNode = this.nodeMap.get(curState);
if(nextNode == null) {
nextNode = new mdtNode();
DBM newDbm = nextNode.merge(stateArray, dbm, nextLevel);
this.nodeMap.put(curState, nextNode);
return newDbm;
}
return nextNode.merge(stateArray, dbm, nextLevel);
}
public DBM getDbm(State[] stateArray, int level) {
if (level == stateArray.length)
return this.dbmSet.getFirst();
State curSt = stateArray[level];
mdtNode nextNode = this.nodeMap.get(curSt);
if (nextNode != null)
return nextNode.getDbm(stateArray, level+1);
return null;
}
public boolean contains(State[] stateArray, DBM dbm, int level) {
if (level == stateArray.length) {
for(DBM existingDbm : this.dbmSet) {
System.out.println(dbm + "\n\n" + existingDbm);
if(dbm.subset(existingDbm)==true)
return true;
}
return false;
}
mdtNode nextNode = this.nodeMap.get(stateArray[level]);
if (nextNode == null)
return false;
System.out.println("level = " + level + ": " + stateArray[level] + " ---> " + nextNode);
return nextNode.contains(stateArray, dbm, level+1);
}
public int pathCount() {
if (this.nodeMap != null) {
int count = 0;
Set<State> stateSet = this.nodeMap.keySet();
for (State curState : stateSet) {
mdtNode nextNode = this.nodeMap.get(curState);
count += nextNode.pathCount();
}
return count;
}
return this.dbmSet.size();
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.common;
import edu.utah.ece.async.lema.verification.platu.BinaryTree.*;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class BinTreeTable extends SetIntTuple {
BinaryTree StateTable = null;
int Size = 0;
public BinTreeTable() {
this.StateTable = new BinaryTree();
this.Size = 0;
}
@Override
public int add(int[] IntArray) {
int newEle = StateTable.add(IntArray);
if(newEle != 0)
this.Size++;
return newEle==-1 ? 0 : 1;
}
@Override
public boolean contains(int[] IntArray) {
return this.StateTable.contains(IntArray);
}
@Override
public int size() {
return this.Size;
}
@Override
public String stats() {
return "Element count = "+ this.StateTable.elementCount() + ", Tree node count = " + this.StateTable.nodeCount();
}
}

View file

@ -0,0 +1,159 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.common;
import java.io.Console;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Collection;
import java.util.HashSet;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Definitions of commonly used constants, and functions for the entire project.
*
* @author ldtwo
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Common {
public static final int INFINITY = Integer.MAX_VALUE;
public static final int LPN_INT_MAX = Integer.MAX_VALUE;
public static final int LPN_INT_MIN = 0;
public static final DecimalFormat FLOAT=new DecimalFormat("00.000");
public static final DecimalFormat LONG=new DecimalFormat("###,###,###,##0");
enum Verif_mode { verif_flat, verif_compositional }{}
enum Timing { timing_untimed, timing_timed }{}
static public void pr(Object o) {
System.out.print(o);
}
static public void prln(Object o) {
System.out.println(o);
}
static public void pErr(Object o) {
System.err.println(o);
}
public static char getChar(){
try {
return (char) System.in.read();
} catch (IOException ex) {
Logger.getLogger(Common.class.getName()).log(Level.SEVERE, null, ex);
return ' ';
}
}
public static boolean brk(Console con) {
char cmd = 'y';
prln("Do you want to continue? y/n");
while (true) {
// prln("simulate " + iterations++ + " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ");
if (con == null) {
break;
}
String line = con.readLine();
if (line == null) {
pErr("line==null");
}
else if (line.length() > 0) {
cmd = line.charAt(0);
if (cmd == 'n' || cmd == 'y') {
break;
}
prln("Wrong command. Try again");
} else {
pErr("type 'y' OR 'n'");
}
}
if (cmd == 'n') {
return false;
}
return true;
}
public static Collection<Integer> toList(int[] arr) {
TreeSet<Integer> l = new TreeSet<Integer>();
for (int i : arr) {
l.add(i);
}
return l;
}
public static<T> Collection<T> toList(T[] arr) {
HashSet<T> l = new HashSet<T>();
for (T i : arr) {
l.add(i);
}
return l;
}
public static int[] toArray(Collection<Integer> set) {
int[] arr = new int[set.size()];
int idx = 0;
for (int i : set) {
arr[idx++] = i;
}
return arr;
}
static final public void forceGarbageCollection() {
// for (int i = 0; i < 5; i++) {
// try {
// Thread.sleep(15);
// garbage(i*1023);
// } catch (Exception ex) {
// Logger.getLogger(Common.class.getName()).log(Level.SEVERE, null, ex);
// }
// }
System.gc();
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(10);
} catch (Exception ex) {
Logger.getLogger(Common.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
/**
* Call this to create garbage for the GC to collect. It will be more likely to
* free other garbage in the heap. THis will give more accurate initial memory
* readings.
* @return
*/
static final int garbage(int l) {
int[] nums = {1, 2, 43, 4, 4, 5, 23, 5, 5, 1, 2, 3, 4, 21, 34, 23, 4};
int tot = 0;
String ss = "";
for (int i : nums) {
for (int j : nums) {
for (int k : nums) {
String s = i + "" + j + "" + k+l;
ss += s;
s += s + s + i;
tot += s.length() + ss.length();
}
}
}
return tot;
}
}

View file

@ -0,0 +1,54 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.common;
import java.util.*;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class HashTable extends SetIntTuple{
HashSet<IntArrayObj> Table;
public HashTable() {
this.Table = new HashSet<IntArrayObj>();
}
@Override
public int add(int[] IntArray) {
boolean existing = this.Table.add(new IntArrayObj(IntArray));
return existing ? 1 : 0;
}
@Override
public boolean contains(int[] IntArray) {
return this.Table.contains(new IntArrayObj(IntArray));
}
@Override
public int size() {
return this.Table.size();
}
@Override
public String stats() {
return "States in state table: " + this.size();
}
}

View file

@ -0,0 +1,79 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.common;
import java.util.HashMap;
import edu.utah.ece.async.lema.verification.platu.common.PlatuObj;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class IndexObjMap<T extends PlatuObj> {
protected HashMap<T, T> uniqueObjTbl;
// TODO: (temp) str2ObjTbl is not used.
// protected HashMap<String, T> str2ObjTbl;
protected HashMap<Integer, T> idx2ObjTbl;
public IndexObjMap() {
uniqueObjTbl = new HashMap<T, T>();
// str2ObjTbl = new HashMap<String, T>();
idx2ObjTbl = new HashMap<Integer, T>();
}
public T add(T obj) {
T objCopy = uniqueObjTbl.get(obj);
if(objCopy != null)
return objCopy;
this.uniqueObjTbl.put(obj, obj);
// String objLabel = obj.getLabel();
// if(objLabel != null){
// if(this.str2ObjTbl.containsKey(objLabel) == false)
// this.str2ObjTbl.put(obj.getLabel(), obj);
// else
// ;// Throw an exception
// }
int idx = this.idx2ObjTbl.size();
try {
if (idx > 2147483647) // Index is greater than the maximum number that int can represents.
throw new Exception();
} catch (Exception e) {
System.out.println("Integer overflow.");
e.printStackTrace();
}
obj.setIndex(idx);
this.idx2ObjTbl.put(idx, obj);
return obj;
}
// public T get(String label) {
// return this.str2ObjTbl.get(label);
// }
public T get(Integer index) {
return this.idx2ObjTbl.get(index);
}
public int size() {
return this.uniqueObjTbl.size();
}
}

View file

@ -0,0 +1,93 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.common;
import java.util.Arrays;
import edu.utah.ece.async.lema.verification.platu.common.PlatuObj;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class IntArrayObj extends PlatuObj {
int index;
int[] IntArray;
public IntArrayObj(int[] intArray) {
super();
index = 0;
IntArray = intArray;
}
public int[] toArray() {
return this.IntArray;
}
@Override
public void setIndex(int Idx) {
this.index = Idx;
}
@Override
public int getIndex() {
return this.index;
}
@Override
public void setLabel(String lbl) {}
@Override
public String getLabel() { return null; }
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(IntArray);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
IntArrayObj other = (IntArrayObj) obj;
if (!Arrays.equals(IntArray, other.IntArray))
return false;
return true;
}
@Override
public String toString() {
if(IntArray == null)
return "()";
String result = "(";
for(int i = 0; i < this.IntArray.length; i++)
result += this.IntArray[i] + ",";
result += ")";
return result;
}
}

View file

@ -0,0 +1,208 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.common;
import java.util.*;
import edu.utah.ece.async.lema.verification.platu.MDD.*;
import edu.utah.ece.async.lema.verification.platu.main.Options;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class MddTable extends SetIntTuple {
protected Mdd mddMgr = null;
mddNode ReachSet;
mddNode buffer;
long nextMemUpBound;
int Size;
static boolean UseBuffer = true;
static boolean MDDBUF_MODE = true;
static int gcIntervalMin = 0;
public MddTable(int TupleLength) {
mddMgr = new Mdd(TupleLength*4);
this.ReachSet = null;
if (UseBuffer == true)
this.buffer = Mdd.newNode();
else
this.buffer = null;
nextMemUpBound = 500000000;
this.Size = 0;
MddTable.MDDBUF_MODE = Options.getStateFormat() == "mddbuf";
}
@Override
public int add(int[] IntArray) {
long curUsedMem = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
//int[] byteVec = toByteArray(IntArray);
int[] byteVec = MddTable.encode(IntArray);
if(MddTable.UseBuffer == true && MddTable.MDDBUF_MODE==true) {
mddMgr.add(this.buffer, byteVec, false);
boolean overThreshold = (Options.getMemUpperBound() - curUsedMem / 1000000) < 200;
if (overThreshold) {
mddMgr.compress(this.buffer);
if (this.ReachSet == null)
this.ReachSet = this.buffer;
else {
mddNode newReachSet = mddMgr.union(this.ReachSet, this.buffer);
if (newReachSet != this.ReachSet) {
mddMgr.remove(this.ReachSet);
this.ReachSet = newReachSet;
}
if (newReachSet != this.ReachSet) {
mddMgr.remove(this.ReachSet);
this.ReachSet = newReachSet;
}
}
mddMgr.remove(this.buffer);
this.buffer = Mdd.newNode();
Runtime.getRuntime().gc();
MddTable.UseBuffer = false;
System.out.println("*** stop buffering");
}
}
else {
if(this.ReachSet==null)
this.ReachSet = Mdd.newNode();
mddMgr.add(this.ReachSet, byteVec, true);
if((Options.getMemUpperBound() - curUsedMem / 1000000) > 400)
MddTable.UseBuffer = true;
}
this.Size++;
return 0;
}
@Override
public boolean contains(int[] IntArray) {
//int[] byteVec = toByteArray(IntArray);
int[] byteVec = MddTable.encode(IntArray);
boolean existing = Mdd.contains(this.ReachSet, byteVec);
if (existing == true)
return true;
if (this.buffer != null)
return Mdd.contains(this.buffer, byteVec);
return false;
}
@Override
public int size() {
return this.Size;
}
@Override
public String stats() {
return "State count: " + this.Size + ", " + "MDD node count: " + this.mddMgr.nodeCnt();
}
/*
* Utilities for search functions
*/
private static int[] toIntArray(int i) {
int[] charArray = new int[4];
int mask = 0x000000FF;
for (int iter = 0; iter < 4; iter++) {
charArray[3 - iter] = (i & mask);
i = i >> 8;
}
return charArray;
}
@SuppressWarnings("unused")
private static int[] toByteArray(int[] intVec) {
//System.out.println(Arrays.toString(intVec));
int[] byteArray = new int[intVec.length*4];
int offset = intVec.length;
int zeros = 0;
for (int i = 0; i < intVec.length; i++) {
int[] result = toIntArray(intVec[i]);
byteArray[i] = result[0];
if(byteArray[i] == 0)
zeros++;
byteArray[offset+i] = result[1];
byteArray[offset*2 + i] = result[2];
byteArray[offset*3 + i] = result[3];
}
int firstNonZero = 0;
for(int i = 0; i < intVec.length*4; i++)
if(byteArray[i] != 0) {
firstNonZero = i;
break;
}
int[] byteArray1 = byteArray;
if(firstNonZero > 0) {
int[] result = new int[intVec.length*4 - firstNonZero];
for(int i = 0; i < result.length; i++)
result[i] = byteArray[i+firstNonZero];
byteArray1 = result;
}
//System.out.println(Arrays.toString(byteArray1)+"\n-----------------------------------------------");
return byteArray;
}
private static int[] encode(int[] intVec) {
int[] codeArray = new int[intVec.length*2];
int offset = intVec.length;
for (int i = 0; i < intVec.length; i++) {
int remainder = intVec[i] & 0x000003FF;
int quotient = intVec[i] >> 10;
codeArray[i] = quotient;
codeArray[offset+i] = remainder;
}
// System.out.println(Arrays.toString(intVec) + "\n--------------" +
// Arrays.toString(codeArray));
return codeArray;
}
@SuppressWarnings("unused")
private static HashSet<IntArrayObj> decompose(int[] IntArray) {
HashSet<IntArrayObj> result = new HashSet<IntArrayObj>();
for (int i = 1; i < IntArray.length-1; i++) {
for (int ii = i+1; ii < IntArray.length; ii++) {
int[] tmp = new int[3];
tmp[0] = IntArray[0];
tmp[1] = IntArray[i];
tmp[2] = IntArray[ii];
result.add(new IntArrayObj(tmp));
}
}
return result;
}
}

View file

@ -0,0 +1,78 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.common;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Pair<LEFT, RIGHT> {
LEFT left;
RIGHT right;
public Pair(LEFT l, RIGHT r) {
this.left = l;
this.right = r;
}
public LEFT getLeft() {
return this.left;
}
public RIGHT getRight() {
return this.right;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((left == null) ? 0 : left.hashCode());
result = prime * result + ((right == null) ? 0 : right.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pair other = (Pair) obj;
if (left == null) {
if (other.left != null)
return false;
}
else if (!left.equals(other.left))
return false;
if (right == null) {
if (other.right != null)
return false;
}
else if (!right.equals(other.right))
return false;
return true;
}
}

View file

@ -0,0 +1,33 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.common;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
abstract public class PlatuObj {
abstract public void setIndex(int Idx);
abstract public int getIndex();
abstract public void setLabel(String lbl);
abstract public String getLabel();
}

View file

@ -0,0 +1,33 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.common;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public abstract class SetIntTuple {
abstract public int add(int[] IntArray);
abstract public boolean contains(int[] IntArray);
abstract public int size();
abstract public String stats();
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class AddNode implements ExpressionNode{
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public AddNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] statevector){
return LeftOperand.evaluate(statevector) + RightOperand.evaluate(statevector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "+" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new AddNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class AndNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public AndNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] statevector){
if(LeftOperand.evaluate(statevector) == 0 || RightOperand.evaluate(statevector) == 0)
return 0;
return 1;
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "&&" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new AndNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,87 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class ArrayElement extends VarNode{
List<ExpressionNode> indexVariables = null;
ArrayNode array = null;
public ArrayElement(ArrayNode array, List<ExpressionNode> indexVars){
super(array.getName());
this.array = array;
this.indexVariables = indexVars;
}
public ArrayNode getArray(){
return this.array;
}
@Override
public int evaluate(int[] statevector){
List<Integer> indexValues = new ArrayList<Integer>(this.indexVariables.size());
for(ExpressionNode n : this.indexVariables){
indexValues.add(n.evaluate(statevector));
}
return this.array.getElement(indexValues).evaluate(statevector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
variables.add(this.array);
}
@Override
public String toString(){
String s = array.getName();
for(ExpressionNode n : this.indexVariables){
s += "[" + n.toString() + "]";
}
return s;
}
@Override
public int getIndex(int[] stateVector){
List<Integer> indexValues = new ArrayList<Integer>(this.indexVariables.size());
for(ExpressionNode n : this.indexVariables){
indexValues.add(n.evaluate(stateVector));
}
return this.array.getElement(indexValues).getIndex(stateVector);
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
List<ExpressionNode> copyList = new ArrayList<ExpressionNode>(this.indexVariables.size());
for(ExpressionNode n : this.indexVariables){
copyList.add(n.copy(variables));
}
return new ArrayElement((ArrayNode) this.array.copy(variables), copyList);
}
}

View file

@ -0,0 +1,161 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class ArrayNode extends VarNode{
private int dimensions = 0;
private List<Object> array = null;
private List<Integer> dimensionList = null;
private List<VarNode> variableList = null;
public ArrayNode(String name, List<Object> array, int dimensions, List<Integer> dimensionList, List<VarNode> variableList){
super(name);
this.array = array;
this.dimensions = dimensions;
this.dimensionList = dimensionList;
this.variableList = variableList;
}
public List<VarNode> getVariableList(){
return this.variableList;
}
public int getDimensions(){
return this.dimensions;
}
public VarNode getElement(int index){
if(this.dimensions != 1 || index < 0 || index > (this.dimensionList.get(0) - 1)){
System.err.println("error: out of bounds array index");
System.exit(1);
}
return (VarNode) this.array.get(index);
}
@SuppressWarnings("unchecked")
public VarNode getElement(List<Integer> indexList){
if(this.dimensions != indexList.size()){
System.err.println("error: incorrect dimensions for array " + this.name);
System.exit(1);
}
int lastIndex = indexList.size() - 1;
lastIndex = indexList.get(lastIndex).intValue();
Object currentArray = this.array;
for(int i = 0; i < indexList.size() - 1; i++){
int index = indexList.get(i);
if(index < 0 || index > (this.dimensionList.get(i) - 1)){
System.err.println("error: out of bounds array index");
System.exit(1);
}
currentArray = ((List<Object>)currentArray).get(index);
}
if(lastIndex < 0 || lastIndex > (this.dimensionList.get(indexList.size() - 1) - 1)){
System.err.println("error: out of bounds array index");
System.exit(1);
}
return (VarNode) ((List<Object>)currentArray).get(lastIndex);
}
@Override
public void getVariables(HashSet<VarNode> variables){
variables.add(this);
}
public List<Integer> getDimensionList(){
return this.dimensionList;
}
@Override
public VarNode clone(){
return new ArrayNode(this.name, this.array, this.dimensions, this.dimensionList, this.variableList);
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
VarNode varNode = variables.get(this.name);
if(varNode != null){
return varNode;
}
int iter = dimensionList.size() - 1;
int dIndex = 0;
int arraySize = dimensionList.get(dIndex++);
int lastSize = 0;
List<Object> topLevelArray = new ArrayList<Object>(arraySize);
Queue<List<Object>> arrayQueue = new LinkedList<List<Object>>();
arrayQueue.offer(topLevelArray);
while(iter > 0){
lastSize = arraySize;
arraySize = dimensionList.get(dIndex++);
int qSize = arrayQueue.size();
for(int i = 0; i < qSize; i++){
List<Object> array = arrayQueue.poll();
for(int j = 0 ; j < lastSize; j++){
List<Object> newArray = new ArrayList<Object>(arraySize);
array.add(j, newArray);
arrayQueue.offer(newArray);
}
}
iter--;
}
dIndex--;
arraySize = dimensionList.get(dIndex);
int nodeIndex = 0;
List<VarNode> varList = new ArrayList<VarNode>();
while(!arrayQueue.isEmpty()){
List<Object> array = arrayQueue.poll();
for(int i = 0; i < arraySize; i++){
VarNode node = this.variableList.get(nodeIndex++);
VarNode newNode = variables.get(node.getName());
if(newNode == null){
newNode = node.clone();
}
array.add(i, newNode);
varList.add(newNode);
}
}
ArrayNode newArray = new ArrayNode(this.name, topLevelArray, this.dimensionList.size(), this.dimensionList, varList);
newArray.setType(this.type);
return newArray;
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class BitAndNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public BitAndNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return LeftOperand.evaluate(stateVector) & RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "&" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new BitAndNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,53 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class BitNegNode implements ExpressionNode {
ExpressionNode RightOperand = null;
public BitNegNode(ExpressionNode rightOperand){
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return ~RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return "~" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new BitNegNode(this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class BitOrNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public BitOrNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return LeftOperand.evaluate(stateVector) | RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "|" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new BitOrNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class BitXorNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public BitXorNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return LeftOperand.evaluate(stateVector) ^ RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "^" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new BitXorNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class ConstNode implements ExpressionNode {
int Value = 0;
String Name;
public ConstNode(String name, int value){
this.Name = name;
this.Value = value;
}
@Override
public int evaluate(int[] stateVector){
return this.Value;
}
@Override
public void getVariables(HashSet<VarNode> variables){
}
@Override
public String toString(){
return "" + Value;
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return this;
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class DivNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public DivNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return LeftOperand.evaluate(stateVector) / RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "/" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new DivNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class EquivNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public EquivNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
if(LeftOperand.evaluate(stateVector) == RightOperand.evaluate(stateVector))
return 1;
return 0;
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "==" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new EquivNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,74 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Expression {
String ExprString = null;
ExpressionNode ExprNode = null;
HashSet<VarNode> Variables = null;
public Expression(ExpressionNode expression){
this.ExprNode = expression;
}
public Expression(ExpressionNode expression, HashSet<VarNode> variables){
this.Variables = variables;
this.ExprNode = expression;
}
public int evaluate(int[] stateVector){
return ExprNode.evaluate(stateVector);
}
public HashSet<VarNode> getVariables(){
if(Variables == null){
Variables = new HashSet<VarNode>();
this.ExprNode.getVariables(Variables);
}
return Variables;
}
@Override
public String toString(){
if(ExprString == null){
ExprString = ExprNode.toString();
}
return ExprString;
}
/**
* Returns a copy of the expression and all subsequent nodes.
* Variable nodes are replaced with the VarNode indexed at it's name
* in the variables HashMap, otherwise a new object is created with
* the same attributes. Constant nodes are not copied.
* @param variables - HashMap of variable nodes keyed with their name
* @return ExpressionNode - New ExpressionNode object
*/
public Expression copy(HashMap<String, VarNode> variables){
return new Expression(this.ExprNode.copy(variables));
}
}

View file

@ -0,0 +1,43 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public interface ExpressionNode {
public int evaluate(int[] stateVector);
public void getVariables(HashSet<VarNode> variables);
@Override
public String toString();
/**
* Returns a copy of the top level node and all subsequent nodes.
* Variable nodes are replaced with the VarNode indexed at it's name
* in the variables HashMap, otherwise a new object is created with
* the same attributes. Constant nodes are not copied.
* @param variables - HashMap of variable nodes keyed with their name
* @return ExpressionNode - New ExpressionNode object
*/
public ExpressionNode copy(HashMap<String, VarNode> variables);
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class GreatEqualNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public GreatEqualNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
if(LeftOperand.evaluate(stateVector) >= RightOperand.evaluate(stateVector))
return 1;
return 0;
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + ">=" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new GreatEqualNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class GreatNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public GreatNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
if(LeftOperand.evaluate(stateVector) > RightOperand.evaluate(stateVector))
return 1;
return 0;
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + ">" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new GreatNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class ImplicationNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public ImplicationNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
if(LeftOperand.evaluate(stateVector) == 0 || RightOperand.evaluate(stateVector) != 0)
return 1;
return 0;
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "->" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new ImplicationNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class LeftShiftNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public LeftShiftNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return LeftOperand.evaluate(stateVector) << RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "<<" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new LeftShiftNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class LessEqualNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public LessEqualNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
if(LeftOperand.evaluate(stateVector) <= RightOperand.evaluate(stateVector))
return 1;
return 0;
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "<=" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new LessEqualNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class LessNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public LessNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
if(LeftOperand.evaluate(stateVector) < RightOperand.evaluate(stateVector))
return 1;
return 0;
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "<" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new LessNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,53 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class MinNode implements ExpressionNode {
ExpressionNode RightOperand = null;
public MinNode(ExpressionNode rightOperand){
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return -RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return "-" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new MinNode(this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class ModNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public ModNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return LeftOperand.evaluate(stateVector) % RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "%" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new ModNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class MultNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public MultNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return LeftOperand.evaluate(stateVector) * RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "*" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new MultNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class NegNode implements ExpressionNode {
ExpressionNode RightOperand = null;
public NegNode(ExpressionNode rightOperand){
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
if(RightOperand.evaluate(stateVector) == 0)
return 1;
return 0;
}
@Override
public void getVariables(HashSet<VarNode> variables){
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return "!" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new NegNode(this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class NotEquivNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public NotEquivNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
if(LeftOperand.evaluate(stateVector) != RightOperand.evaluate(stateVector))
return 1;
return 0;
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "!=" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new NotEquivNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,59 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class OrNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public OrNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
if(LeftOperand.evaluate(stateVector) != 0 || RightOperand.evaluate(stateVector) != 0)
return 1;
return 0;
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "||" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new OrNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class RightShiftNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public RightShiftNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return LeftOperand.evaluate(stateVector) >> RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + ">>" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new RightShiftNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,56 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class SubNode implements ExpressionNode {
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public SubNode(ExpressionNode leftOperand, ExpressionNode rightOperand){
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
return LeftOperand.evaluate(stateVector) - RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return LeftOperand.toString() + "-" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new SubNode(this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,61 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class TernaryNode implements ExpressionNode {
ExpressionNode Condition = null;
ExpressionNode LeftOperand = null;
ExpressionNode RightOperand = null;
public TernaryNode(ExpressionNode condition, ExpressionNode leftOperand, ExpressionNode rightOperand){
this.Condition = condition;
this.LeftOperand = leftOperand;
this.RightOperand = rightOperand;
}
@Override
public int evaluate(int[] stateVector){
if(this.Condition.evaluate(stateVector) != 0)
return LeftOperand.evaluate(stateVector);
return RightOperand.evaluate(stateVector);
}
@Override
public void getVariables(HashSet<VarNode> variables){
LeftOperand.getVariables(variables);
RightOperand.getVariables(variables);
}
@Override
public String toString(){
return Condition + "?" + LeftOperand.toString() + ":" + RightOperand.toString();
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
return new TernaryNode(this.Condition.copy(variables), this.LeftOperand.copy(variables), this.RightOperand.copy(variables));
}
}

View file

@ -0,0 +1,114 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.expression;
import java.util.HashMap;
import java.util.HashSet;
import edu.utah.ece.async.lema.verification.platu.platuLpn.VarType;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class VarNode implements ExpressionNode {
protected String name; // if input, associated output var name
protected String alias = ""; // if input, original var name
protected VarType type = VarType.INTERNAL;
protected int value = 0;
protected int index = -1;
public VarNode(String name){
this.name = name;
}
public VarNode(String name, int index){
this.name = name;
this.index = index;
}
public void setName(String name){
this.name = name;
}
public void setType(VarType type){
this.type = type;
}
public VarType getType(){
return this.type;
}
public void setAlias(String alias){
this.alias = alias;
}
public String getAlias(){
return this.alias;
}
public String getName(){
return this.name;
}
public int evaluate(){
return this.value;
}
@Override
public int evaluate(int[] stateVector){
return stateVector[this.index];
}
public void setIndex(int index){
this.index = index;
}
// TODO: No need to pass in the stateVector for this method.
public int getIndex(int[] stateVector){
return this.index;
}
@Override
public void getVariables(HashSet<VarNode> variables){
variables.add(this);
}
@Override
public String toString(){
return name;
}
@Override
public VarNode clone(){
VarNode cloneNode = new VarNode(this.name, this.index);
cloneNode.setAlias(this.alias);
cloneNode.setType(this.type);
return cloneNode;
}
@Override
public ExpressionNode copy(HashMap<String, VarNode> variables){
VarNode node = variables.get(this.name);
if(node == null){
node = this.clone();
}
return node;
}
}

View file

@ -0,0 +1,200 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.logicAnalysis;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class CompositeState{
private int[] stateTuple = null;
private List<CompositeStateTran> incomingStateTranList = new LinkedList<CompositeStateTran>();
private List<CompositeStateTran> outgoingStateTranList = new LinkedList<CompositeStateTran>();
private String label = null;
private int index = 0;
public void addIncomingStateTran(CompositeStateTran incomingTran){
this.incomingStateTranList.add(incomingTran);
}
public boolean removeIncomingStateTran(CompositeStateTran incomingTran){
return this.incomingStateTranList.remove(incomingTran);
}
public boolean removeOutgoingStateTran(CompositeStateTran outgoingTran){
return this.outgoingStateTranList.remove(outgoingTran);
}
public List<CompositeStateTran> getIncomingStateTranList(){
return this.incomingStateTranList;
}
public void addOutgoingStateTran(CompositeStateTran outgoingTran){
this.outgoingStateTranList.add(outgoingTran);
}
public List<CompositeStateTran> getOutgoingStateTranList(){
return this.outgoingStateTranList;
}
public int numIncomingTrans(){
return this.incomingStateTranList.size();
}
public int numOutgoingTrans(){
return this.outgoingStateTranList.size();
}
public CompositeState(int[] stateArray){
this.stateTuple = stateArray;
}
/**
* Adds a state transition from this state.
* @param lpnTran - LPN transition causing the state transition
* @param cState - Next state
* @return The next CompositeState object already associated with the LPNTran, otherwise null.
*/
// public CompositeState addNextStateTran(LPNTran lpnTran, CompositeState cState){
// return this.nextStateMap.put(lpnTran, cState);
// }
/**
* Adds a state transition to this state.
* @param lpnTran - LPN transition causing the state transition
* @param cState - Previous state
* @return The previous CompositeState object already associated with the LPNTran, otherwise null.
*/
// public CompositeState addPreviousStateTran(LPNTran lpnTran, CompositeState cState){
// return this.previousStateMap.put(lpnTran, cState);
// }
// public void setTranArray(LPNTran[] tranArray){
// this.tranArray = tranArray;
// }
//
// public LPNTran[] getTranArray(){
// return this.tranArray;
// }
//
// public void setNextStateArray(CompositeState[] nextStateArray){
// this.nextStateArray = nextStateArray;
// }
//
// public CompositeState[] getNextStateArray(){
// return this.nextStateArray;
// }
public void setLabel(String lbl){
this.label = lbl;
}
public String getLabel(){
if(this.label == null){
this.label = "";
for(int i = 0; i < this.stateTuple.length; i++){
label += this.stateTuple[i];
if(i < this.stateTuple.length - 1){
label += ",";
}
}
}
return this.label;
}
public void setIndex(int idx){
this.index = idx;
}
public int getIndex(){
return this.index;
}
public void clear(){
this.outgoingStateTranList.clear();
this.incomingStateTranList.clear();
}
@Override
public String toString(){
return "" + getIndex();
}
public int getSize(){
return this.stateTuple.length;
}
public int[] getStateTuple(){
return this.stateTuple;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(stateTuple);
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CompositeState other = (CompositeState) obj;
if (!Arrays.equals(stateTuple, other.stateTuple))
return false;
return true;
}
// public void addEdge(CompositeStateTran edge){
// this.edgeList.add(edge);
// }
// public void addTran(LPNTran lpnTran){
// this.tranList.add(lpnTran);
// }
//
// public void addNextState(CompositeState st){
// this.nextStateList.add(st);
// }
// public List<CompositeStateTran> getEdgeList(){
// return this.edgeList;
// }
// public List<LPNTran> getTranList(){
// return this.tranList;
// }
//
// public List<CompositeState> getNextStateList(){
// return this.nextStateList;
// }
}

View file

@ -0,0 +1,330 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.logicAnalysis;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import edu.utah.ece.async.lema.verification.lpn.Transition;
import edu.utah.ece.async.lema.verification.platu.main.Options;
import edu.utah.ece.async.lema.verification.platu.stategraph.State;
import edu.utah.ece.async.lema.verification.platu.stategraph.StateGraph;
import java.util.Set;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class CompositeStateGraph {
public Map<Integer, CompositeState> indexStateMap = new HashMap<Integer, CompositeState>();
public Map<CompositeState, CompositeState> stateMap = new HashMap<CompositeState, CompositeState>();
public Map<CompositeStateTran, CompositeStateTran> stateTranMap = new HashMap<CompositeStateTran, CompositeStateTran>();
private StateGraph[] stateGraphArray = null;
private CompositeState initState = null;
private String label = "";
public StateGraph[] getStateGraphArray(){
return this.stateGraphArray;
}
public void setReachableStates(Map<Integer, CompositeState> indexMap, Map<CompositeState, CompositeState> stateMap){
this.indexStateMap = indexMap;
this.stateMap = stateMap;
}
public static List<Transition> getEnabled(CompositeState currentState){
//Set<Transition> lpnTranSet = new HashSet<Transition>(currentState.numOutgoingTrans());
List<Transition> enabled = new ArrayList<Transition>(currentState.numOutgoingTrans());
/*
for(CompositeStateTran stTran : currentState.getOutgoingStateTranList()){
// TODO: (future) Fix stTran.getLPNTran().
Transition lpnTran = null; //stTran.getLPNTran();
if(lpnTranSet.add(lpnTran))
enabled.add(lpnTran);
}
*/
return enabled;
}
public CompositeState getState(int index){
return this.indexStateMap.get(index);
}
public CompositeStateTran addStateTran(CompositeState currentState, CompositeState nextState, Transition lpnTran){
CompositeStateTran stateTran = new CompositeStateTran(currentState, nextState, lpnTran);
CompositeStateTran tmpTran = this.stateTranMap.get(stateTran);
if(tmpTran != null){
return tmpTran;
}
this.stateTranMap.put(stateTran, stateTran);
currentState.addOutgoingStateTran(stateTran);
nextState.addIncomingStateTran(stateTran);
return stateTran;
}
public CompositeStateTran addStateTran(int currentStateIndex, int nextStateIndex, Transition lpnTran){
CompositeState currentState = this.indexStateMap.get(currentStateIndex);
CompositeState nextState = this.indexStateMap.get(nextStateIndex);
CompositeStateTran stateTran = new CompositeStateTran(currentState, nextState, lpnTran);
CompositeStateTran tmpTran = this.stateTranMap.get(stateTran);
if(tmpTran != null){
return tmpTran;
}
this.stateTranMap.put(stateTran, stateTran);
currentState.addOutgoingStateTran(stateTran);
nextState.addIncomingStateTran(stateTran);
return stateTran;
}
public CompositeStateTran addStateTran(CompositeStateTran stateTran){
CompositeStateTran tmpTran = this.stateTranMap.get(stateTran);
if(tmpTran != null){
return tmpTran;
}
this.stateTranMap.put(stateTran, stateTran);
CompositeState currentState = this.getState(stateTran.getCurrentState());
CompositeState nextState = this.getState(stateTran.getNextState());
currentState.addOutgoingStateTran(stateTran);
nextState.addIncomingStateTran(stateTran);
return stateTran;
}
public void removeStateTran(CompositeStateTran stateTran){
if(this.stateTranMap.remove(stateTran) == null){
return;
}
CompositeState currentState = this.getState(stateTran.getCurrentState());
CompositeState nextState = this.getState(stateTran.getNextState());
currentState.removeOutgoingStateTran(stateTran);
nextState.removeIncomingStateTran(stateTran);
}
public boolean removeState(CompositeState st){
CompositeState retState = this.stateMap.remove(st);
if(retState == null){
return false;
}
this.indexStateMap.remove(st.getIndex());
return true;
}
public boolean removeState(int stateIndex){
CompositeState retState = this.indexStateMap.remove(stateIndex);
if(retState == null){
return false;
}
this.stateMap.remove(retState);
return true;
}
public CompositeStateGraph(CompositeState initialState, StateGraph[] sgArray){
this.initState = initialState;
this.stateGraphArray = sgArray;
//int size = 0;
for(int i = 0; i < sgArray.length; i++){
label += sgArray[i].getLpn().getLabel();
if(i < sgArray.length - 1){
label += "||";
}
//size *= sgArray[i].reachSize();
}
this.addState(this.initState);
}
public CompositeStateGraph(StateGraph sg){
int[] initStateArray = new int[1];
initStateArray[0] = sg.getInitialState().getIndex();
CompositeState init = new CompositeState(initStateArray);
StateGraph[] sgArray = new StateGraph[1];
sgArray[0] = sg;
// initialize attributes
this.initState = init;
this.stateGraphArray = sgArray;
// construct label
//int size = 0;
for(int i = 0; i < sgArray.length; i++){
label += sgArray[i].getLpn().getLabel();
if(i < sgArray.length - 1){
label += "||";
}
//size *= sgArray[i].reachSize();
}
this.addState(this.initState);
CompositeState tempState = null;
for(int i = 0; i < sg.reachSize(); i++){
State currentState = sg.getState(i);
// for(State currentState : sg.getStateSet()){
int[] currentStateArray = new int[1];
currentStateArray[0] = currentState.getIndex();
CompositeState currentCompositeState = new CompositeState(currentStateArray);
tempState = this.addState(currentCompositeState);
if(tempState != currentCompositeState){
currentCompositeState = tempState;
}
Set<Entry<Transition, State>> stateSet = sg.getOutgoingTrans(currentState);
for(Entry<Transition, State> stateTran : stateSet){
State nextState = stateTran.getValue();
Transition lpnTran = stateTran.getKey();
int[] nextStateArray = new int[1];
nextStateArray[0] = nextState.getIndex();
CompositeState nextCompositeState = new CompositeState(nextStateArray);
tempState = this.addState(nextCompositeState);
if(tempState != nextCompositeState){
nextCompositeState = tempState;
}
CompositeStateTran newStateTran = new CompositeStateTran(currentCompositeState, nextCompositeState, lpnTran);
this.addStateTran(newStateTran);
if(!lpnTran.isLocal()){
newStateTran.setVisibility();
}
}
}
}
public Set<CompositeState> getStateSet(){
return this.stateMap.keySet();
}
public int getSize(){
return this.stateGraphArray.length;
}
public String getLabel(){
return this.label;
}
/**
* Adds a composite state to the composite state graph
* @param st - CompositeState to be added
* @return Equivalent CompositeState object it exists, otherwise CompositeState st.
*/
public CompositeState addState(CompositeState st){
CompositeState retState = this.stateMap.get(st);
if(retState == null){
int index = this.indexStateMap.size();
st.setIndex(index);
this.indexStateMap.put(index, st);
this.stateMap.put(st, st);
return st;
}
return retState;
}
public final CompositeState getInitState(){
return this.initState;
}
public void setInitState(CompositeState init){
this.initState = init;
}
public int numStates(){
return this.stateMap.size();
}
public int numStateTrans(){
return this.stateTranMap.size();
}
public Set<CompositeStateTran> getStateTranSet(){
return this.stateTranMap.keySet();
}
public boolean containsState(int stateIndex){
return this.indexStateMap.containsKey(stateIndex);
}
public boolean containsStateTran(CompositeStateTran stateTran){
return this.stateTranMap.containsKey(stateTran);
}
public void draw(){
String dotFile = Options.getDotPath();
if(!dotFile.endsWith("/") && !dotFile.endsWith("\\")){
String dirSlash = "/";
if(System.getProperty("os.name").toLowerCase().contains("windows")) dirSlash = "\\";
dotFile = dotFile += dirSlash;
}
dotFile += this.label + ".dot";
PrintStream graph = null;
try {
graph = new PrintStream(new FileOutputStream(dotFile));
} catch (FileNotFoundException e1) {
e1.printStackTrace();
return;
}
graph.println("digraph SG{");
for(CompositeState currentState : this.stateMap.keySet()){
for(CompositeStateTran stateTran : currentState.getOutgoingStateTranList()){
CompositeState nextState = this.indexStateMap.get(stateTran.getNextState());
Transition lpnTran = stateTran.getLPNTran();
// System.out.println(" " + nextState.getIndex());
graph.println(" \"" + currentState.getIndex() + "\" " + " -> " + "\"" + nextState.getIndex() + "\"" + " [label=\"" + lpnTran.getFullLabel() + "\"]");
}
}
graph.println("}");
graph.close();
}
}

View file

@ -0,0 +1,115 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.logicAnalysis;
import edu.utah.ece.async.lema.verification.lpn.Transition;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class CompositeStateTran {
private int nextState = 0;
private int currentState = 0;
private Transition lpnTransition = null;
private boolean visible = false;
public CompositeStateTran(CompositeState currentState, CompositeState nextState, Transition lpnTran){
this.currentState = currentState.getIndex();
this.nextState = nextState.getIndex();
this.lpnTransition = lpnTran;
}
public CompositeStateTran(int currentState, int nextState, Transition lpnTransition){
this.currentState = currentState;
this.nextState = nextState;
this.lpnTransition = lpnTransition;
}
public void setVisibility(){
this.visible = true;
}
public boolean visible(){
return this.visible;
}
public void setCurrentState(int currState){
this.currentState = currState;
}
public void setNextState(int nxtState){
this.nextState = nxtState;
}
public void setLpnTran(Transition lpnTran){
this.lpnTransition = lpnTran;
}
public int getCurrentState(){
return this.currentState;
}
public int getNextState(){
return this.nextState;
}
public Transition getLPNTran(){
return this.lpnTransition;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + this.nextState;
result = prime * result + this.lpnTransition.hashCode();
result = prime * result + this.currentState;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
CompositeStateTran other = (CompositeStateTran) obj;
if (this.nextState != other.nextState)
return false;
if (this.lpnTransition != other.lpnTransition)
return false;
if (this.currentState != other.currentState)
return false;
return true;
}
@Override
public String toString(){
return (this.currentState + " --" + this.lpnTransition.getFullLabel() + "--> " + this.nextState);
}
}

View file

@ -0,0 +1,208 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.logicAnalysis;
import java.util.ArrayList;
import java.util.List;
import edu.utah.ece.async.lema.verification.lpn.LPN;
import edu.utah.ece.async.lema.verification.lpn.Transition;
import edu.utah.ece.async.lema.verification.platu.stategraph.StateGraph;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class CompositionalThread extends Thread{
private StateGraph[] srcArray = null;
private StateGraph sg = null;
private int iter = 0;
private int newTransitions = 0;
public CompositionalThread(StateGraph sg, StateGraph[] srcArray, int iter){
this.srcArray = srcArray;
this.sg = sg;
this.iter = iter;
}
public int getNewTransitions(){
return this.newTransitions;
}
public StateGraph getStateGraph(){
return this.sg;
}
@Override
public void run(){
List<Constraint> newConstraintSet = new ArrayList<Constraint>();
List<Constraint> oldConstraintSet = new ArrayList<Constraint>();
for(StateGraph srcSG : this.srcArray){
extractConstraints(sg, srcSG, newConstraintSet, oldConstraintSet);
newTransitions += applyConstraintSet(sg, srcSG, iter, newConstraintSet, oldConstraintSet);
}
}
/**
* Applies new constraints to the entire state set, and applies old constraints to the frontier state set.
* @return Number of new transitions.
*/
private static int applyConstraintSet(StateGraph sg, StateGraph srcSG, int iter, List<Constraint> newConstraintSet, List<Constraint> oldConstraintSet){
int newTransitions = 0;
// int[] thisIndexList = null;
// int[] otherIndexList = null;
//
// String label = srcSG.getLabel();
// String[] indexArray = sg.getKeyArray();
//
// for(int i = 0; i < indexArray.length; i++){
// if(label == indexArray[i]){
// thisIndexList = sg.getThisIndexArray(i);
// otherIndexList = sg.getOtherIndexArray(i);
// break;
// }
// }
// int index = sg.getInterfaceIndex(srcSG.getLabel());
// int[] thisIndexList = sg.getThisIndexArray(index);
// int[] otherIndexList = sg.getOtherIndexArray(index);
//LhpnFile srcLpn = srcSG.getLpn();
//LhpnFile lpn = sg.getLpn();
// TODO: (future)need to add getThisIndexArray in LhpnFile.
/*
int[] thisIndexList = lpn.getThisIndexArray(srcLpn.ID);
int[] otherIndexList = lpn.getOtherIndexArray(srcLpn.ID);
if(newConstraintSet.size() > 0){
for(Object obj : sg.getStateSet().toArray()){
platu.stategraph.State currentState = (platu.stategraph.State) obj;
for(Constraint c : newConstraintSet){
if(compatible(currentState, c, thisIndexList, otherIndexList)){
newTransitions += createNewState(sg, currentState, c);
}
}
}
for(platu.stategraph.State currentState : sg.getFrontierStateSet()){
for(Constraint c : newConstraintSet){
if(compatible(currentState, c, thisIndexList, otherIndexList)){
newTransitions += createNewState(sg, currentState, c);
}
}
}
}
if(oldConstraintSet.size() > 0){
for(platu.stategraph.State currentState : sg.getFrontierStateSet()){
for(Constraint c : oldConstraintSet){
if(compatible(currentState, c, thisIndexList, otherIndexList)){
newTransitions += createNewState(sg, currentState, c);
}
}
}
}
*/
return newTransitions;
}
/**
* Extracts applicable constraints from a StateGraph.
* @param sg The state graph the constraints are to be applied.
* @param srcSG The state graph the constraint are extracted from.
*/
private static void extractConstraints(StateGraph sg, StateGraph srcSG, List<Constraint> newConstraintSet, List<Constraint> oldConstraintSet){
newConstraintSet.clear();
oldConstraintSet.clear();
LPN srcLpn = srcSG.getLpn();
for(Constraint newConstraint : sg.getNewConstraintSet()){
if(newConstraint.getLpn() != srcLpn) continue;
newConstraintSet.add(newConstraint);
}
for(Constraint oldConstraint : sg.getOldConstraintSet()){
if(oldConstraint.getLpn() != srcLpn) continue;
oldConstraintSet.add(oldConstraint);
}
}
/**
* Determines whether a constraint is compatible with a state.
* @return True if compatible, otherwise False.
*/
@SuppressWarnings("unused")
private static boolean compatible(edu.utah.ece.async.lema.verification.platu.stategraph.State currentState, Constraint constr, int[] thisIndexList, int[] otherIndexList){
int[] constraintVector = constr.getVector();
int[] currentVector = currentState.getVariableVector();
for(int i = 0; i < thisIndexList.length; i++){
int thisIndex = thisIndexList[i];
int otherIndex = otherIndexList[i];
if(currentVector[thisIndex] != constraintVector[otherIndex]){
return false;
}
}
return true;
}
/**
* Creates a state from a given constraint and compatible state. If the state is new, then findSG is called.
* @return Number of new transitions.
*/
@SuppressWarnings("unused")
private static int createNewState(StateGraph sg, edu.utah.ece.async.lema.verification.platu.stategraph.State compatibleState, Constraint c){
int newTransitions = 0;
// Create new state and insert into state graph
edu.utah.ece.async.lema.verification.platu.stategraph.State newState = new edu.utah.ece.async.lema.verification.platu.stategraph.State(compatibleState);
int[] newVector = newState.getVariableVector();
//List<VarNode> variableList = c.getVariableList();
List<Integer> variableList = c.getVariableList();
List<Integer> valueList = c.getValueList();
//int[] compatibleVector = compatibleState.getVector();
for(int i = 0; i < variableList.size(); i++){
//int index = variableList.get(i).getIndex(compatibleVector);
int index = variableList.get(i);
newVector[index] = valueList.get(i);
}
edu.utah.ece.async.lema.verification.platu.stategraph.State nextState = sg.addState(newState);
if(nextState == newState){
int result = sg.synchronizedConstrFindSG(nextState);
if(result < 0) return newTransitions;
// sg.initializeTranList(nextState);
newTransitions += result;
}
// StateTran stTran = new StateTran(compatibleState, constraintTran, state);
Transition constraintTran = c.getLpnTransition();
// constraintTran.synchronizedAddStateTran(compatibleState, nextState);
// sg.addEnabledTran(compatibleState, constraintTran);
newTransitions++;
return newTransitions;
}
}

View file

@ -0,0 +1,169 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.logicAnalysis;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import edu.utah.ece.async.lema.verification.lpn.LPN;
import edu.utah.ece.async.lema.verification.lpn.Transition;
import edu.utah.ece.async.lema.verification.platu.platuLpn.DualHashMap;
import edu.utah.ece.async.lema.verification.platu.stategraph.State;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class Constraint{
private LPN lpn; // lpn that generates the constraint
final private int[] interfaceValues;
final private Transition lpnTransition;
final private int[] vector;
//List<VarNode> variableList = new ArrayList<VarNode>(1);
List<Integer> variableList = new ArrayList<Integer>(1); // variableList stores the index of interface variables in the other lpn.
List<Integer> valueList = new ArrayList<Integer>(1);
private int hashVal = -1;
public Constraint(State start, State end, Transition firedTran, LPN lpn2) {
this.lpnTransition = firedTran;
this.lpn = firedTran.getLpn();
this.vector = start.getVariableVector();
int[] endVector = end.getVariableVector();
// int index = dstLpn.getInterfaceIndex(this.lpn.getLabel());
//int[] thisIndex = lpn2.getOtherIndexArray(this.lpn.ID-1);
int[] thisIndex = lpn2.getOtherIndexArray(this.lpn.getLpnIndex());
DualHashMap<String, Integer> varIndexMap = this.lpn.getVarIndexMap();
this.interfaceValues = new int[thisIndex.length];
for(int i = 0; i < thisIndex.length; i++){
int varIndex = thisIndex[i];
this.interfaceValues[i] = this.vector[varIndex];
if(this.vector[varIndex] != endVector[varIndex]){
String variable = varIndexMap.getKey(varIndex);
this.valueList.add(endVector[varIndex]);
this.variableList.add(lpn2.getVarIndexMap().get(variable));
//this.variableList.add(lpn2.getVarNodeMap().get(variable));
}
}
if(this.variableList.size() == 0){
System.out.println(this.lpnTransition.getFullLabel());
System.err.println("error: invalid constraint");
System.exit(1);
}
}
/**
* @return List of modified variables.
*/
public List<Integer> getVariableList(){
return this.variableList;
}
/**
* @return List of new variable values.
*/
public List<Integer> getValueList(){
return this.valueList;
}
/**
* @return State vector.
*/
public int[] getVector(){
return this.vector;
}
/**
* @return LPN where the constraint was generated.
*/
public LPN getLpn(){
return this.lpn;
}
/**
* @return Values of the interface variables.
*/
public int[] getInterfaceValue(){
return this.interfaceValues;
}
/**
* @return LPNTran applied.
*/
public Transition getLpnTransition(){
return this.lpnTransition;
}
@Override
public int hashCode() {
if(this.hashVal == -1){
final int prime = 31;
this.hashVal = 1;
this.hashVal = prime * this.hashVal + Arrays.hashCode(interfaceValues);
this.hashVal = prime * this.hashVal + ((this.lpn == null) ? 0 : this.lpn.getLabel().hashCode());
this.hashVal = prime * this.hashVal + ((this.lpnTransition == null) ? 0 : this.lpnTransition.hashCode());
}
return this.hashVal;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Constraint other = (Constraint) obj;
if (!Arrays.equals(this.interfaceValues, other.interfaceValues))
return false;
if (this.lpn == null) {
if (other.lpn != null)
return false;
}
else if (!this.lpn.equals(other.lpn))
return false;
if (this.lpnTransition == null) {
if (other.lpnTransition != null)
return false;
}
else if (!this.lpnTransition.equals(other.lpnTransition))
return false;
return true;
}
@Override
public String toString() {
return "Constraint [lpn=" + lpn.getLabel() + ",\n interfaceValues="
+ Arrays.toString(interfaceValues) + ",\n lpnTransition="
+ lpnTransition + ",\n vector=" + Arrays.toString(vector)
+ ",\n variableList=" + variableList + ",\n valueList=" + valueList
+ "]";
}
}

View file

@ -0,0 +1,55 @@
/*******************************************************************************
*
* This file is part of iBioSim. Please visit <http://www.async.ece.utah.edu/ibiosim>
* for the latest version of iBioSim.
*
* Copyright (C) 2017 University of Utah
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the Apache License. A copy of the license agreement is provided
* in the file named "LICENSE.txt" included with this software distribution
* and also available online at <http://www.async.ece.utah.edu/ibiosim/License>.
*
*******************************************************************************/
package edu.utah.ece.async.lema.verification.platu.logicAnalysis;
import java.util.HashSet;
import edu.utah.ece.async.lema.verification.platu.project.PrjState;
/**
*
*
* @author
* @author Chris Myers
* @author <a href="http://www.async.ece.utah.edu/ibiosim#Credits"> iBioSim Contributors </a>
* @version %I%
*/
public class HashSetWrapper extends HashSet<PrjState> implements StateSetInterface {
private static final long serialVersionUID = 1L;
@Override
public boolean contains(PrjState state) {
return super.contains(state);
}
@Override
public boolean add(PrjState state) {
return super.add(state);
}
/**
* This method takes a PrjState instance otherPrjState, iterates through this hash set of PrjState instances,
* and grabs the one from this set that "equals" to otherPrjState. If no match is found, this method returns null.
* @param otherPrjState
* @return
*/
public PrjState get(PrjState otherPrjState) {
for (PrjState prjSt : this) {
if (this.contains(otherPrjState))
return prjSt;
}
return null;
}
}

Some files were not shown because too many files have changed in this diff Show more