Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
droplet-sequence-generator
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Peter Wagenhuber
droplet-sequence-generator
Commits
83025f7e
Commit
83025f7e
authored
7 years ago
by
Peter Wagenhuber
Browse files
Options
Downloads
Patches
Plain Diff
jetzt geht mal das generieren der possibleSequences
parent
ba96749d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Nloc.java
+25
-80
25 additions, 80 deletions
src/Nloc.java
src/TestNloc.java
+55
-110
55 additions, 110 deletions
src/TestNloc.java
with
80 additions
and
190 deletions
src/Nloc.java
+
25
−
80
View file @
83025f7e
...
...
@@ -7,6 +7,8 @@ import java.util.Iterator;
import
java.util.Arrays
;
import
java.lang.Math
;
import
java.util.ConcurrentModificationException
;
import
java.util.concurrent.ThreadLocalRandom
;
public
class
Nloc
{
...
...
@@ -49,7 +51,7 @@ public class Nloc {
dropletSequence
=
generateDropletListRecursive
(
new
ArrayList
<
Droplet
>(),
currentSeq
,
currentSeq
.
get
(
0
).
getMinPos
());
currentSeq
=
resetPayloadDropletPosition
(
currentSeq
);
//
currentSeq = resetPayloadDropletPosition(currentSeq);
}
while
(!
possibleSequences
.
isEmpty
()
&&
dropletSequence
.
size
()
!=
currentSeq
.
size
()
&&
!
this
.
sequenceFunctinal
());
...
...
@@ -180,19 +182,12 @@ public class Nloc {
List
<
List
<
SequenceTuple
>>
oldsequences
;
do
{
oldsequences
=
new
ArrayList
<
List
<
SequenceTuple
>>(
sequences
);
//System.out.println("oldseq: " + oldsequences);
//System.out.println("");
List
<
List
<
SequenceTuple
>>
tmpSeqs
=
new
ArrayList
<
List
<
SequenceTuple
>>();
//System.out.println("sequences before for computing: " + sequences);
//System.out.println("");
for
(
List
<
SequenceTuple
>
stl:
sequences
)
{
tmpSeqs
.
addAll
(
this
.
computeSequences
(
stl
));
}
sequences
=
tmpSeqs
;
//System.out.println("sequences after for computing: " + sequences);
//System.out.println("");
//System.out.println("");
}
while
(
sequences
.
size
()
!=
oldsequences
.
size
());
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
...
...
@@ -200,53 +195,6 @@ public class Nloc {
return
sequences
;
}
//public List<List<SequenceTuple>> getPossibleSequences(
// String[] modulesToVisit) throws NoSuchModuleException {
// Droplet payloadDroplet = new Droplet(DropletType.PAYLOAD,"p");
// List<List<SequenceTuple>> sequences = new ArrayList<List<SequenceTuple>>();
// List<List<Channel>> pathlist = this.getAllPaths();
// try {
// // Create initial list of possilbe sequences
// List<Channel> moduleChanList =
// this.getModulesByName(Arrays.asList(modulesToVisit));
// List<Channel> payloadPath = this.getDesiredPath(moduleChanList, pathlist);
// SequenceTuple plt = new SequenceTuple(payloadDroplet,payloadPath,0,0);
// Channel previousBifurcation = plt.getPreviousBifurcation();
// plt.setCurrentBifurcation(previousBifurcation);
// List<SequenceTuple> s1 = new ArrayList<SequenceTuple>();
// s1.add(plt);
// sequences.add(s1);
// List<Channel> bifurcationList = this.getBifurcationList(payloadPath);
// // actually compile list of sequences going through the bifurcations from
// // "end" to "start"
// //for (int i = bifurcationList.size() - 1; i >= 0; --i) {
// //Channel currentBifurcation = bifurcationList.get(i);
// List<List<SequenceTuple>> oldsequences;
// do {
// oldsequences = new ArrayList<List<SequenceTuple>>(sequences);
// List<List<SequenceTuple>> tmpSeqs = new ArrayList<List<SequenceTuple>>();
// for (List<SequenceTuple> stl: sequences) {
// tmpSeqs.addAll(
// this.computeSequences(stl));
// }
// sequences = tmpSeqs;
// } while (sequences.size() != oldsequences.size());
// //}
// } catch (Exception e) {
// System.out.println( e.getMessage());
// }
// return sequences;
// }
public
void
addChannel
(
Channel
chan
)
{
chanlist
.
add
(
chan
);
}
...
...
@@ -290,13 +238,9 @@ public class Nloc {
public
void
moveDroplets
()
throws
CoalescedDropletException
{
Droplet
[]
drArr
=
this
.
dropletList
.
toArray
(
new
Droplet
[
dropletList
.
size
()]);
for
(
Droplet
dr
:
drArr
)
{
//System.out.println("Droplet: " + dr.getName() + " Position: " + dr.getPosition().getChannel().getName() + ":" + dr.getPosition().getSteps());
dr
.
move
();
//System.out.println("Droplet: " + dr.getName() + " Position: " + dr.getPosition().getChannel().getName() + ":" + dr.getPosition().getSteps());
}
//System.out.println("");
for
(
Droplet
dr:
drArr
)
{
//System.out.println("Droplet: " + dr.getName() + " Position: " + dr.getPosition().getChannel().getName() + ":" + dr.getPosition().getSteps());
if
(
dr
.
coalesce
())
{
throw
new
CoalescedDropletException
(
dr
);
}
...
...
@@ -435,7 +379,6 @@ public class Nloc {
SequenceTuple
currentSeqTup
=
seqTupList
.
get
(
currentSeqTupIndex
);
Channel
currentBifurcation
=
currentSeqTup
.
getCurrentBifurcation
();
//currentSeqTup.setCurrentBifurcation(currentSeqTup.getPreviousBifurcation());
List
<
Channel
>
dropletPath
=
currentSeqTup
.
getPath
();
Channel
bifurcSuccessor
=
...
...
@@ -452,7 +395,6 @@ public class Nloc {
if
(
dropletPath
.
contains
(
currentBifurcation
)
&&
prio
>
0
&&
!(
currentBifurcation
instanceof
Pump
))
{
//System.out.println("we need header");
// we need header droplet
// cirst check all possible paths of header droplets
...
...
@@ -463,22 +405,18 @@ public class Nloc {
setCurrentBifurcation
(
currentSeqTup
.
getPreviousBifurcation
());
for
(
List
<
Channel
>
path:
pathList
)
{
//System.out.println("iterating through pathlist");
List
<
SequenceTuple
>
tmp
=
new
ArrayList
<
SequenceTuple
>();
for
(
SequenceTuple
stup:
seqTupList
)
{
tmp
.
add
(
new
SequenceTuple
(
stup
));
}
String
randHeaderName
=
"h-"
+
ThreadLocalRandom
.
current
().
nextInt
(
1000
,
10000
);
SequenceTuple
tmpTuple
=
new
SequenceTuple
(
new
Droplet
(
DropletType
.
HEADER
,
"h"
),
path
,
currentBifurcation
);
new
SequenceTuple
(
new
Droplet
(
DropletType
.
HEADER
,
randHeaderName
)
,
path
,
currentBifurcation
);
tmpTuple
.
setCurrentBifurcation
(
tmpTuple
.
getPreviousBifurcation
());
tmp
.
add
(
tmpTuple
);
//System.out.println("tmp:");
//for (SequenceTuple tstu: tmp) {
// System.out.println("tstu: " + tstu);
//}
// calculate and set pump offsets
int
minPos
=
currentSeqTup
.
getMinPos
();
...
...
@@ -498,8 +436,6 @@ public class Nloc {
int
minPathLenNewDroplet
=
maxPathLenNewDroplet
-
defaultChan
.
getHSteps
()
+
1
;
//System.out.println("minPos: " + minPos + " pathLenCurrDroplet: " +
// pathLenCurrDroplet + " minPathLenNewDroplet: " + minPathLenNewDroplet);
int
newTupleMinPos
=
minPos
-
(
pathLenCurrDroplet
-
minPathLenNewDroplet
);
int
newTupleMaxPos
=
...
...
@@ -509,34 +445,39 @@ public class Nloc {
tmpTuple
.
setMaxPos
(
newTupleMaxPos
);
possibleSequences
.
add
(
tmp
);
//System.out.println("adding tmp to possible sequences " + possibleSequences);
}
}
else
if
(!(
currentBifurcation
instanceof
Pump
))
{
// we still have some bifurcations to check
currentSeqTup
.
setCurrentBifurcation
(
currentSeqTup
.
getPreviousBifurcation
());
getSequencesAtBifurcationRecursive
(
seqTupList
,
currentSeqTupIndex
,
possibleSequences
);
}
else
{
//System.out.println("else");
possibleSequences
.
add
(
seqTupList
);
}
}
else
{
//possibleSequences.add(seqTupList);
if
(
dropletPath
.
contains
(
currentBifurcation
)
&&
prio
>
0
&&
!(
currentBifurcation
instanceof
Pump
))
{
//System.out.println("we need header for: " + currentSeqTup.getDroplet() + " " + currentSeqTup.getDroplet().getName());
//System.out.println("At: " + currentBifurcation.getName());
// we need header droplet
// cirst check all possible paths of header droplets
Channel
defaultChan
=
currentBifurcation
.
getChildrenList
().
get
(
0
);
List
<
List
<
Channel
>>
pathList
=
this
.
getAllPathsFromTo
(
dropletPath
.
get
(
0
),
defaultChan
);
currentSeqTup
.
setCurrentBifurcation
(
currentSeqTup
.
getPreviousBifurcation
());
for
(
List
<
Channel
>
path:
pathList
)
{
//List<SequenceTuple> tmp = new ArrayList<SequenceTuple>(seqTupList);
List
<
SequenceTuple
>
tmp
=
new
ArrayList
<
SequenceTuple
>();
for
(
SequenceTuple
stup:
seqTupList
)
{
tmp
.
add
(
new
SequenceTuple
(
stup
));
}
String
randHeaderName
=
"h-"
+
ThreadLocalRandom
.
current
().
nextInt
(
1000
,
10000
);
SequenceTuple
tmpTuple
=
new
SequenceTuple
(
new
Droplet
(
DropletType
.
HEADER
,
"h"
),
path
,
currentBifurcation
);
new
SequenceTuple
(
new
Droplet
(
DropletType
.
HEADER
,
randHeaderName
)
,
path
,
currentBifurcation
);
tmpTuple
.
setCurrentBifurcation
(
tmpTuple
.
getPreviousBifurcation
());
...
...
@@ -560,8 +501,6 @@ public class Nloc {
int
minPathLenNewDroplet
=
maxPathLenNewDroplet
-
defaultChan
.
getHSteps
()
+
1
;
//System.out.println("minPos: " + minPos + " pathLenCurrDroplet: " +
// pathLenCurrDroplet + " minPathLenNewDroplet: " + minPathLenNewDroplet);
int
newTupleMinPos
=
minPos
-
(
pathLenCurrDroplet
-
minPathLenNewDroplet
);
int
newTupleMaxPos
=
...
...
@@ -573,6 +512,12 @@ public class Nloc {
getSequencesAtBifurcationRecursive
(
tmp
,
currentSeqTupIndex
+
1
,
possibleSequences
);
}
}
else
if
(!(
currentBifurcation
instanceof
Pump
))
{
// we still have some bifurcations to check
currentSeqTup
.
setCurrentBifurcation
(
currentSeqTup
.
getPreviousBifurcation
());
getSequencesAtBifurcationRecursive
(
seqTupList
,
currentSeqTupIndex
,
possibleSequences
);
}
else
{
getSequencesAtBifurcationRecursive
(
seqTupList
,
currentSeqTupIndex
+
1
,
possibleSequences
);
...
...
This diff is collapsed.
Click to expand it.
src/TestNloc.java
+
55
−
110
View file @
83025f7e
...
...
@@ -10,104 +10,32 @@ public class TestNloc {
public
static
void
main
(
String
[]
args
)
{
//Nloc nl = new Nloc(getNlocS5());
//
//TODO: this
//List<Channel> chList = getNlocSTestLast(); //getNlocSXX();
List
<
Channel
>
chList
=
getNlocSXX
();
//getNlocSXX();
List
<
Channel
>
chList
=
getNlocS2
();
//getNlocSXX();
Nloc
nl
=
new
Nloc
(
chList
);
//Pump pump = nl.getPump();
//pump.setSteps(2);
//Channel c1 = new Channel("ch1", 3, 5);
//Sink s0 = new Sink();
//Channel c2 = new Channel("ch2", 3, 5);
//Module m0 = new Module("m0", 5,1);
//c1.addChild(c2);
//Droplet pld = new Droplet(DropletType.PAYLOAD, new Position(pump,1));
//pld.setName("p");
//Droplet hdr = new Droplet(DropletType.HEADER, new Position(pump,2));
//hdr.setName("h");
//
//System.out.println(pld.coalesce());
//
//int normStep = hdr.getNormalizedSteps();
//System.out.println("Normalized Steps: " + normStep);
//nl.setDropletList(pump.getDropletList());
//if (nl.simulate()) {
// System.out.println("Success!! Don't coalesce");
//} else {
// System.out.println("Did coalesce!");
//}
//TODO: this
List
<
List
<
Channel
>>
allPaths
=
nl
.
getAllPaths
();
printPaths
(
allPaths
);
//allPaths.remove(4);
//try {
// String[] mtv = {"f2", "m3", "h0", "m5"};
// List<List<SequenceTuple>> posSeqs = nl.getPossibleSequences(mtv);
// //printSequences(posSeqs);
// System.out.println("DEBUG:");
// Pump p0 = nl.getShortestSequence(mtv);
// printPumpcontents(p0);
//} catch (Exception e) {
// System.out.println(e.getMessage());
//}
//printPaths(allPaths);
//TODO: this
//String[] mtv = {"h3", "m1", "m3", "m0", "m5"};
//try {
// List<List<SequenceTuple>> stll = nl.getPossibleSequences(mtv);
// printSequences(stll);
//} catch (NoSuchModuleException e) {
// System.out.println(e.getMessage());
//}
int
count
=
0
;
for
(
List
<
Channel
>
path:
allPaths
)
{
String
[]
modulesToVisit
=
extractModuleStringArrayFromPath
(
path
);
System
.
out
.
println
(
"Pathnum: "
+
count
++);
System
.
out
.
println
(
"Modules to visit: "
);
for
(
String
str:
modulesToVisit
)
{
System
.
out
.
print
(
str
+
" "
);
}
System
.
out
.
println
(
"
Pathnum: "
+
count
++
);
System
.
out
.
println
(
"
"
);
try
{
List
<
List
<
SequenceTuple
>>
stll
=
nl
.
getPossibleSequences
(
modulesToVisit
);
printSequences
(
stll
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
//
Pump p = nl.getShortestSequence(modulesToVisit);
//
printPumpcontents(p);
Pump
p
=
nl
.
getShortestSequence
(
modulesToVisit
);
printPumpcontents
(
p
);
}
//Droplet pld = new Droplet(DropletType.PAYLOAD,"p");
//Droplet hdr = new Droplet(DropletType.HEADER,"h");
//List<Droplet> drlist = new ArrayList<Droplet>();
//drlist.add(pld);
//drlist.add(hdr);
//List<Droplet> newlist = new ArrayList<Droplet>();
//for (Droplet dr: drlist) {
// newlist.add(new Droplet(dr));
//}
//System.out.println("Printing original list:");
//for (Droplet dr: drlist) {
// System.out.println("Droplet: " + dr);
//}
//System.out.println("Printing copy of list:");
//for (Droplet dr: newlist) {
// System.out.println("Droplet: " + dr);
//}
}
public
static
void
printPumpcontents
(
Pump
pump
)
{
...
...
@@ -1092,75 +1020,92 @@ public class TestNloc {
// channel(name, psteps, hsteps)
Channel
ch1
=
new
Channel
(
"ch1"
,
1
,
1
);
Channel
ch2
=
new
Channel
(
"ch2"
,
1
,
1
);
Channel
ch3
=
new
Channel
(
"ch3"
,
3
,
3
);
Channel
ch4
=
new
Channel
(
"ch4"
,
1
,
1
);
Channel
ch3
=
new
Channel
(
"ch3"
,
1
,
1
);
Channel
ch4
=
new
Channel
(
"ch4"
,
3
,
3
);
Channel
ch5
=
new
Channel
(
"ch5"
,
1
,
1
);
Channel
ch6
=
new
Channel
(
"ch6"
,
1
,
1
);
Channel
ch7
=
new
Channel
(
"ch7"
,
1
,
1
);
Channel
ch8
=
new
Channel
(
"ch8"
,
3
,
3
);
Channel
ch8
=
new
Channel
(
"ch8"
,
1
,
1
);
Channel
ch9
=
new
Channel
(
"ch9"
,
1
,
1
);
Channel
ch10
=
new
Channel
(
"ch10"
,
1
,
1
);
Channel
ch10
=
new
Channel
(
"ch10"
,
3
,
3
);
Channel
ch11
=
new
Channel
(
"ch11"
,
1
,
1
);
Channel
ch12
=
new
Channel
(
"ch12"
,
3
,
3
);
Channel
ch12
=
new
Channel
(
"ch12"
,
1
,
1
);
Channel
ch13
=
new
Channel
(
"ch13"
,
1
,
1
);
Channel
ch14
=
new
Channel
(
"ch14"
,
1
,
1
);
Channel
ch15
=
new
Channel
(
"ch15"
,
1
,
1
);
Channel
ch15
=
new
Channel
(
"ch15"
,
3
,
3
);
Channel
ch16
=
new
Channel
(
"ch16"
,
1
,
1
);
Channel
ch17
=
new
Channel
(
"ch17"
,
1
,
1
);
Channel
ch18
=
new
Channel
(
"ch18"
,
1
,
1
);
Channel
ch19
=
new
Channel
(
"ch19"
,
1
,
1
);
Channel
ch20
=
new
Channel
(
"ch20"
,
1
,
1
);
Module
m0
=
new
Module
(
"m0"
,
5
,
1
);
Module
m1
=
new
Module
(
"m1"
,
5
,
1
);
Module
m2
=
new
Module
(
"m2"
,
5
,
1
);
Module
m3
=
new
Module
(
"m3"
,
5
,
1
);
Module
h0
=
new
Module
(
"h0"
,
5
,
1
);
Module
h1
=
new
Module
(
"h1"
,
5
,
1
);
Module
d0
=
new
Module
(
"d0"
,
5
,
1
);
Module
d1
=
new
Module
(
"d1"
,
5
,
1
);
Pump
p0
=
new
Pump
();
Sink
s0
=
new
Sink
();
List
<
Channel
>
chlist
=
Arrays
.
asList
(
ch1
,
ch2
,
ch3
,
ch4
,
ch5
,
ch6
,
ch7
,
ch8
,
ch9
,
ch10
,
ch11
,
ch12
,
ch13
,
ch14
,
ch15
,
ch16
,
ch17
,
m0
,
m1
,
m2
,
m3
,
h0
,
p0
,
s0
);
ch9
,
ch10
,
ch11
,
ch12
,
ch13
,
ch14
,
ch15
,
ch16
,
ch17
,
ch18
,
ch19
,
ch20
,
m0
,
m1
,
m2
,
m3
,
h0
,
h1
,
d0
,
d1
,
p0
,
s0
);
p0
.
addChild
(
ch1
);
p0
.
addChild
(
ch2
);
p0
.
addChild
(
ch
17
);
p0
.
addChild
(
ch
3
);
ch1
.
addChild
(
ch3
);
ch1
.
addChild
(
ch4
);
ch1
.
addChild
(
ch5
);
ch
3
.
addChild
(
m0
);
m0
.
addChild
(
ch
6
);
ch
4
.
addChild
(
m0
);
m0
.
addChild
(
ch
7
);
ch
2
.
addChild
(
h
0
);
h
0
.
addChild
(
ch
5
);
ch
5
.
addChild
(
h
1
);
h
1
.
addChild
(
ch
8
);
ch2
.
addChild
(
h0
);
h0
.
addChild
(
ch6
);
ch
17
.
addChild
(
ch
7
);
ch
5
.
addChild
(
ch
7
);
ch
6
.
addChild
(
ch
9
);
ch
3
.
addChild
(
ch
9
);
ch
7
.
addChild
(
ch
8
);
ch
7
.
addChild
(
ch
9
);
ch
9
.
addChild
(
ch
10
);
ch
9
.
addChild
(
ch
11
);
ch
8
.
addChild
(
m1
);
m1
.
addChild
(
ch1
0
);
ch
10
.
addChild
(
m1
);
m1
.
addChild
(
ch1
2
);
ch10
.
addChild
(
ch11
);
ch9
.
addChild
(
ch11
);
ch6
.
addChild
(
ch11
);
ch4
.
addChild
(
ch11
);
ch11
.
addChild
(
d0
);
d0
.
addChild
(
ch13
);
ch11
.
addChild
(
ch12
);
ch11
.
addChild
(
ch13
);
ch7
.
addChild
(
ch14
);
ch8
.
addChild
(
ch14
);
ch12
.
addChild
(
ch14
);
ch13
.
addChild
(
ch14
);
ch12
.
addChild
(
m2
);
m2
.
addChild
(
ch14
);
ch14
.
addChild
(
ch15
);
ch13
.
addChild
(
ch15
);
ch14
.
addChild
(
ch16
);
ch15
.
addChild
(
m2
);
m2
.
addChild
(
ch17
);
ch16
.
addChild
(
d1
);
d1
.
addChild
(
ch18
);
ch17
.
addChild
(
ch19
);
ch18
.
addChild
(
ch19
);
ch15
.
addChild
(
m3
);
m3
.
addChild
(
ch16
);
ch19
.
addChild
(
m3
);
m3
.
addChild
(
ch20
);
ch20
.
addChild
(
s0
);
ch16
.
addChild
(
s0
);
return
chlist
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment