Commit 55ecd56b authored by kreller's avatar kreller
Browse files

upload source code

parent 0e0ea00e
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="lib" level="project" />
</component>
</module>
\ No newline at end of file
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
Autocode5
===
#Background
Autocode5 is an implementation of GXW synthesis tool. AC5 allows numeric variables and comparison clauses in GXW
specifications. AC5 will generate a python program according to the input GXW specifications.
For details in GXW theory, see the [paper](https://link.springer.com/chapter/10.1007/978-3-319-41528-4_6).
For the former implementation see [here](https://sourceforge.net/projects/autocode4/).
#Download and Installation
For the source code, download or clone the `srccode` folder. The source folder can be simply open by most modern
Java IDE.
For the binary tool, download the `release` folder only.
To run AC5, the environmental requirements are as follows:
- Java 11+
- [Yices](https://github.com/SRI-CSL/yices2) 2.6.4+
- [Lingua Franca](https://github.com/lf-lang/lingua-franca) 0.7.0+
The CLI tool of Lingua Franca `lfc` is attached in the release folder.
#Usage
After downloading or cloning, go into the release directory, use
java -jar Autocode5.jar example.txt
A `model.lf` file will be generated in the current directory. This is the synthesized model of input specifications.
Then go into the `lfc` directory, run
./lfc ../model.lf
A python program will be generated in `release/src-gen/model/model.py`.
#License
The redistribution and use of Autocode5 are permitted under LGPLv3.
\ No newline at end of file
target Python;
import GI,inub,andGate,GO,iff,iftb,cmp_Out,cmp_In,resNum,trub,resBool from "actors.lf";
preamble
{=
import portion as P
import random
=}
main reactor
{
GIin1 = new GI(var="in1")
GIin2 = new GI(var="in2")
GOout1 = new GO(var="out1")
GOout2 = new GO(var="out2")
GOout3 = new GO(var="out3")
GOout4 = new GO(var="out4")
Ctrl_0 = new iftb()
Ctrl_1 = new iff()
AND_Event_1 = new andGate(size=2)
Ctrl_2 = new trub()
Cmp2_1_out = new cmp_Out(size=0,expr="out3>0",op=">")
Cmp2_2_in = new cmp_In(size=1,expr="in0=0")
Cmp2_3_in = new cmp_In(size=1,expr="in0=0")
Ctrl_3 = new inub()
Cmp3_1_out = new cmp_Out(size=0,expr="out4=0",op="=")
Resout1 = new resBool(size=1)
Resout2 = new resBool(size=1)
Resout3 = new resNum(size=1)
Resout4 = new resNum(size=1)
GIin1.out->Ctrl_0._in
AND_Event_1.out->Ctrl_1._in
Ctrl_2.out->Cmp2_1_out._set
Cmp2_2_in.out->Ctrl_2._trigger
Cmp2_3_in.out->Ctrl_2._release
Ctrl_3.out->Cmp3_1_out._set
GOout2.out->Ctrl_3._in
Resout1.out->GOout1._in
Resout2.out->GOout2._in
Resout3.out->GOout3._in
Resout4.out->GOout4._in
Ctrl_0.out->Resout1._in
Cmp2_1_out.out->Resout3._in
Ctrl_1.out->Resout2._in
Cmp3_1_out.out->Resout4._in
GOout4.out->Cmp2_3_in._in
GIin2.out->Cmp2_2_in._in
GIin1.out,GOout1.out->AND_Event_1._in
}
target Python
reactor GI(var(""))
{
output out
timer t(0, 1sec)
reaction (t)->out
{=
try:
a=float(input(f"{self.var}: "))
out.set(a)
except:
out.set(-1)
=}
}
/*
reactor GI(var(""))
{
output out
timer t(0, 0)
reaction (t)->out
{=
try:
a=float(input(f"{self.var}: "))
out.set(a)
except:
out.set(-1)
=}
}
*/
reactor GO(var(""))
{
input _in
output out
reaction (_in)->out
{=
print(f"[OUTPUT]{self.var}: {_in.value}")
out.set(_in.value)
=}
}
reactor notGate
{
input _in
output out
reaction (_in)->out
{=
out.set(_in.value)
if _in.value==1:
out.set(0)
elif _in.value==0:
out.set(1)
=}
}
reactor andGate(size(1))
{
input[size] _in
output out
reaction (_in)->out
{=
out.set(-1)
for var in _in:
if var.value==1:
out.set(1)
elif var.value==0:
out.set(0)
break
=}
}
reactor orGate(size(1))
{
input[size] _in
output out
reaction (_in)->out
{=
out.set(-1)
for var in _in:
if var.value==1:
out.set(1)
break
elif var.value==0:
out.set(0)
=}
}
reactor iftb
{
input _in
output out
reaction (_in)->out
{=
if _in.value==1:
out.set(1)
else:
out.set(-1)
=}
}
reactor iff
{
input _in
output out
reaction (_in)->out
{=
if _in.value==1:
out.set(1)
elif _in.value==0:
out.set(0)
else:
out.set(_in.value)
=}
}
reactor trub
{
input _trigger
input _release
output out
state lock(False)
reaction (_trigger, _release)->out
{=
if _trigger.is_present and _release.is_present:
if _trigger.value==1 and _release.value==0:
out.set(1)
self.lock = True
elif self.lock and _release.value==0:
out.set(1)
elif self.lock and _release.value==1:
out.set(-1)
self.lock = False
else:
out.set(-1)
=}
}
reactor inub
{
input _in
output out
state lock(False)
reaction (_in)->out
{=
out.set(1)
if self.lock:
out.set(-1)
elif _in.value==1:
out.set(-1)
self.lock = True
elif _in.value==0:
out.set(1)
=}
}
reactor risingMonitor
{
preamble
{=
list = []
=}
input _in
output out
reaction (_in)->out
{=
self.list.insert(0,_in.value)
if len(self.list)>=2 and self.list[0]==1 and self.list[1]==0:
out.set(1)
else:
out.set(0)
=}
}
reactor fallingMonitor
{
preamble
{=
list = []
=}
input _in
output out
reaction (_in)->out
{=
self.list.insert(0,_in.value)
if len(self.list)>=2 and self.list[0]==0 and self.list[1]==1:
out.set(1)
else:
out.set(0)
=}
}
reactor complexMonitor(size(1),spec(""),highestX(0))
{
input[size] _in
output out
state lists({=[[] for i in range(self.size)]=})
reaction (_in)->out
{=
tempstr = self.spec
vars = tempstr.split("&&")
xnum = []
notVar = []
for i in range(len(vars)):
num = len(vars[i])-len(vars[i].replace("X", ""))
xnum.append(num)
vars[i] = vars[i].replace("X", "")
if vars[i].startswith("!"):
notVar.append(0)
else:
notVar.append(1)
for i in range(self.size):
self.lists[i].insert(0, _in[i].value)
if len(self.lists[0])>self.highestX:
hold = True
for i in range(len(vars)):
index = int(vars[i].replace("in",""))
if self.lists[index][self.highestX-xnum[i]]!=notVar[i]:
hold = False
break
if hold:
out.set(1)
else:
out.set(0)
else:
out.set(0)
=}
}
reactor cmp_In(size(1),expr(""))
{
input[size] _in
output out
reaction (_in)->out
{=
tempexpr = str(self.expr)
for i in range(self.size):
tempexpr = tempexpr.replace("in"+str(i),str(_in[i].value))
if eval(tempexpr):
out.set(1)
else:
out.set(0)
=}
}
reactor cmp_Out(size(1),expr(""),op(""))
{
input _set
input[size] _in
output out
reaction (_set)_in->out
{=
if _set.value!=1:
out.set("NaN")
else:
vars = self.expr.split(self.op,1)
tempexpr = vars[1]
for i in range(self.size):
tempexpr = tempexpr.replace("in"+str(i),str(_in[i].value))
result = eval(tempexpr)
tempout = self.op+str(result)
out.set(tempout)
=}
}
reactor adjust(count(0))
{
input _set
input _in
output out
state firstSet(False)
state cnt(0)
reaction (_set, _in)->out
{=
if _set.is_present and _in.is_present:
if _set.value==0 and not self.firstSet:
out.set(0)
elif _set.value==1:
out.set(0)
self.fiestSet = True
self.cnt = self.count-1
else:
if self.cnt>0:
out.set(0)
self.cnt-=1
else:
out.set(_in.value)
=}
}
reactor resBool(size(1))
{
input[size] _in
output out
reaction (_in)->out
{=
out.set(-1)
for var in _in:
if var.value==1:
out.set(1)
elif var.value==0:
out.set(0)
=}
}
reactor resNum(size(1))
{
input[size] _in
output out
reaction (_in)->out
{=
resP = P.open(-P.inf, P.inf)
for i in range(self.size):
tempstr = _in[i].value
if tempstr.startswith(">="):
num = float(tempstr.replace(">=",""))
tempP = P.closedopen(num, P.inf)
resP = resP&tempP
elif tempstr.startswith(">"):
num = float(tempstr.replace(">",""))
tempP = P.open(num, P.inf)
resP = resP&tempP
elif tempstr.startswith("<="):
num = float(tempstr.replace("<=",""))
tempP = P.openclosed(-P.inf, num)
resP = resP&tempP
elif tempstr.startswith("<"):
num = float(tempstr.replace("<",""))
tempP = P.open(-P.inf, num)
resP = resP&tempP
elif tempstr.startswith("="):
num = float(tempstr.replace("=",""))
tempP = P.singleton(num)
resP = resP&tempP
elif tempstr.startswith("!="):
num = float(tempstr.replace("!=",""))
tempP = P.singleton(num)
resP = resP-tempP
if resP.empty:
print("!")
elif resP.lower == -P.inf and resP.upper == P.inf:
print("!")
elif resP.lower==resP.upper:
out.set(resP.lower)
print(out.value)
else:
if resP.lower == -P.inf:
out.set(resP.upper-1)
print(out.value)
elif resP.upper == P.inf:
out.set(resP.lower+1)
print(out.value)
else:
out.set(random.randint(int(resP.lower), int(resP.upper)))
print(resP)