Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cosyverif
Services
service adt2amas
Commits
a2bcf7eb
Commit
a2bcf7eb
authored
Dec 09, 2020
by
Jaime Arias
Browse files
feature: add scheduling tables to service response
parent
1c1af04c
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/cosyverif/service/adt2amas/MinimalScheduling.java
View file @
a2bcf7eb
...
...
@@ -5,6 +5,7 @@ import java.io.BufferedWriter;
import
java.io.File
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.FilenameFilter
;
import
java.io.IOException
;
import
java.nio.file.Paths
;
...
...
@@ -40,15 +41,17 @@ public class MinimalScheduling extends BinaryService {
formalism
=
"http://formalisms.cosyverif.org/adtree.fml"
)
private
Model
modelParameter
;
@Parameter
(
name
=
"Scheduling Table"
,
help
=
"String parameter help message."
,
direction
=
Direction
.
OUT
,
multiline
=
true
)
@Parameter
(
name
=
"Scheduling Information"
,
help
=
"Scheduling information for each generated graph."
,
direction
=
Direction
.
OUT
,
multiline
=
true
)
private
String
outputParameter
=
""
;
@Parameter
(
name
=
"Number of graphs"
,
help
=
"
String parameter help message.
"
,
direction
=
Direction
.
OUT
)
@Parameter
(
name
=
"Number of graphs"
,
help
=
"
Number of graphs generated by the counter nodes
"
,
direction
=
Direction
.
OUT
)
private
int
nGraphs
=
0
;
@Parameter
(
name
=
"Scheduling Table"
,
help
=
"Formatted table with the minimal scheduling"
,
direction
=
Direction
.
OUT
,
contenttype
=
"plain/text"
)
private
File
outputTables
=
null
;
@Launch
public
Task
executeBinary
()
throws
IOException
{
parser
=
GrmlParser
.
create
(
modelParameter
);
...
...
@@ -69,6 +72,7 @@ public class MinimalScheduling extends BinaryService {
public
void
fallback
(
String
line
){
try
{
outputParameter
=
formatResult
(
model
);
outputTables
=
getTables
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
...
...
@@ -106,10 +110,11 @@ public class MinimalScheduling extends BinaryService {
while
(
this
.
nGraphs
>
0
&&
(
line
=
br
.
readLine
())
!=
null
)
{
// find a graph info
if
(
line
.
startsWith
(
"Graph #"
)
||
line
.
startsWith
(
"# Agents:"
)
||
line
.
startsWith
(
"# Slots:"
))
{
if
(
line
.
startsWith
(
"#"
))
{
s
.
append
(
" - "
);
}
if
(
line
.
startsWith
(
"Graph #"
))
{
s
.
append
(
line
+
" => "
);
}
else
if
(
line
.
startsWith
(
"# Agents:"
))
{
s
.
append
(
line
+
" - "
);
}
else
if
(
line
.
startsWith
(
"# Slots:"
))
{
s
.
append
(
line
);
}
...
...
@@ -118,7 +123,7 @@ public class MinimalScheduling extends BinaryService {
s
.
append
(
"\n"
);
}
}
fw
.
append
(
"data:\n"
+
s
);
fw
.
append
(
"data:\n"
+
s
+
"\n"
);
}
catch
(
Exception
e
)
{
fw
.
append
(
"error: "
+
e
.
getMessage
()
+
"\n"
);
e
.
printStackTrace
();
...
...
@@ -134,6 +139,59 @@ public class MinimalScheduling extends BinaryService {
return
s
.
toString
();
}
private
File
getTables
()
throws
IOException
{
File
fileOutput
=
null
;
BufferedWriter
bw
=
null
;
FileWriter
fw
=
null
;
String
line
;
BufferedReader
br
=
null
;
FileReader
fr
=
null
;
File
directory
=
new
File
(
baseDirectory
().
getAbsolutePath
());
File
[]
files
=
{};
try
{
files
=
directory
.
listFiles
(
new
FilenameFilter
()
{
public
boolean
accept
(
File
dir
,
String
name
)
{
return
name
.
endsWith
(
".txt"
)
&&
!
name
.
equals
(
"tables.txt"
);
}
});
fileOutput
=
new
File
(
baseDirectory
().
getAbsolutePath
()
+
"/tables.txt"
);
fw
=
new
FileWriter
(
fileOutput
);
bw
=
new
BufferedWriter
(
fw
);
for
(
File
f
:
files
)
{
bw
.
write
(
f
.
getName
()
+
"\n"
);
fr
=
new
FileReader
(
f
);
br
=
new
BufferedReader
(
fr
);
while
((
line
=
br
.
readLine
())
!=
null
)
{
bw
.
write
(
line
);
bw
.
newLine
();
}
bw
.
newLine
();
fr
.
close
();
br
.
close
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
bw
!=
null
)
bw
.
close
();
if
(
fw
!=
null
)
fw
.
close
();
if
(
br
!=
null
)
br
.
close
();
if
(
fr
!=
null
)
fr
.
close
();
}
return
fileOutput
;
}
@Example
(
name
=
"Example of the minimal scheduling algorithm"
,
help
=
"Example of the minimal scheduling algorithm"
)
public
MinimalScheduling
example
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment