Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DEv-CF model
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KIEU Thi phuong
DEv-CF model
Commits
6d0d7074
Commit
6d0d7074
authored
5 months ago
by
KIEU Thi phuong
Browse files
Options
Downloads
Patches
Plain Diff
Generator atomic model
parent
9bfc03bd
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/AMGenerator.java
+128
-0
128 additions, 0 deletions
src/AMGenerator.java
with
128 additions
and
0 deletions
src/AMGenerator.java
0 → 100644
+
128
−
0
View file @
6d0d7074
package
carfollowing_2024_05_02
;
import
java.io.BufferedReader
;
import
java.io.FileReader
;
import
java.io.IOException
;
import
DEVSModel.DEVSAtomic
;
import
DEVSModel.Port
;
public
class
AMGenerator
extends
DEVSAtomic
{
Port
carGen
;
enum
Phase
{
generate
,
stop
};
Phase
phase
;
private
float
sigma
,
time
;
static
int
numCar
=
10
;
static
int
numTestFile
=
9
;
static
String
test
=
"input/input"
;
static
String
filePath
=
test
+
String
.
valueOf
(
numCar
)+
"_"
+
String
.
valueOf
(
numTestFile
)+
".txt"
;
String
line
=
""
;
BufferedReader
reader
=
null
;
public
AMGenerator
(
String
name
)
{
this
.
name
=
name
;
carGen
=
new
Port
(
this
,
"car_generated"
);
this
.
addOutPort
(
carGen
);
// 2024_04_17 read input from file
try
{
reader
=
new
BufferedReader
(
new
FileReader
(
filePath
));
reader
.
readLine
();
// Read header line
}
catch
(
IOException
ex
)
{
ex
.
printStackTrace
();
}
}
@Override
public
void
deltaExt
(
Port
arg0
,
Object
arg1
,
float
arg2
)
{
// nothing to do
}
@Override
public
void
deltaInt
()
{
// if (countCar < numCar) {
// countCar ++;
// }
// else phase = Phase.stop;
// 2024_04_17
System
.
out
.
println
(
"---deltaInt---"
+
this
.
name
);
try
{
line
=
reader
.
readLine
();
}
catch
(
IOException
ex
)
{
ex
.
printStackTrace
();
}
if
(
line
==
null
)
phase
=
Phase
.
stop
;
System
.
out
.
println
(
phase
);
}
@Override
public
float
getDuration
()
{
// 2024_04_17 edit for input duration time
// System.out.println("---getDuration---" + this.name);
if
(
phase
==
Phase
.
stop
)
return
Float
.
POSITIVE_INFINITY
;
else
{
String
[]
fields
=
line
.
split
(
" "
);
return
Integer
.
parseInt
(
fields
[
0
]);
}
}
@Override
public
void
init
()
{
/* Init state: Generate */
phase
=
Phase
.
generate
;
time
=
0
;
sigma
=
0
;
try
{
line
=
reader
.
readLine
();
}
catch
(
IOException
ex
)
{
ex
.
printStackTrace
();
}
if
(
line
!=
null
)
{
String
[]
fields
=
line
.
split
(
" "
);
sigma
=
Integer
.
parseInt
(
fields
[
0
]);
}
}
@Override
public
Object
[]
lambda
()
{
/* Output an object include:
* obj[0] : port
* obj[1] : carGen object with id, init speed, departure time */
// Test 2024_04_17 read input from files
time
+=
getDuration
();
System
.
out
.
println
(
"---lamda---"
+
this
.
name
);
System
.
out
.
println
(
"Time: "
+
time
);
String
id
=
""
;
int
speed
=
0
;
String
[]
fields
=
line
.
split
(
" "
);
id
=
fields
[
1
];
speed
=
Integer
.
parseInt
(
fields
[
2
]);
System
.
out
.
println
(
"*** Car("
+
id
+
") generated"
);
Object
[]
obj
=
new
Object
[
2
];
obj
[
0
]
=
this
.
carGen
;
obj
[
1
]
=
new
Car
(
id
,
speed
,
time
);
return
obj
;
}
}
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