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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KIEU Thi phuong
DEv-CF model
Commits
96e9317b
Commit
96e9317b
authored
4 months ago
by
KIEU Thi phuong
Browse files
Options
Downloads
Patches
Plain Diff
Car object
parents
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
Car.java
+142
-0
142 additions, 0 deletions
Car.java
with
142 additions
and
0 deletions
Car.java
0 → 100644
+
142
−
0
View file @
96e9317b
package
carfollowing_2024_05_02
;
import
java.util.ArrayList
;
public
class
Car
{
/* This car has below variables:
* (String) id
* (int) speedCurrent : current speed (m/s)
* (int) speedDesire : desire speed (m/s)
* (float) departureTime : departure time (s)
* (float) arrivalTime : arrival time (s)
* (float) position : curent position (m)
* (float) t : time reaching end of road from current position (s)
* (float) deltaT : time reaching front car from current position (s) */
int
DistaceBetweenCar
=
3
;
int
CarLenght
=
2
;
String
id
;
int
speedCurrent
,
speedDesire
;
float
departureTime
,
arrivalTime
;
float
t
;
float
deltaT
=
Float
.
POSITIVE_INFINITY
;
float
position
=
0
;
float
watingTime
=
0
;
// Test 2024_04_09
public
ArrayList
<
String
>
listSpeed
=
new
ArrayList
();
public
ArrayList
<
String
>
listPosition
=
new
ArrayList
();
public
Car
(
String
name
,
int
speed
,
float
time
)
{
super
();
this
.
id
=
name
;
this
.
speedDesire
=
speed
;
this
.
speedCurrent
=
speed
;
this
.
departureTime
=
time
;
}
public
String
toString
()
{
return
(
"Car "
+
this
.
id
+
", "
+
"speed "
+
this
.
speedCurrent
+
"m/s, "
+
"departure time "
+
this
.
departureTime
+
"s, "
+
"arrival time "
+
this
.
arrivalTime
+
"s"
);
}
// For test 2024_04_06
public
String
getID
()
{
return
this
.
id
;
}
// Set initial speed when a car enters road
public
void
setSpeed
(
int
speed
)
{
if
(
speedDesire
<
speed
)
speedCurrent
=
speedDesire
;
else
speedCurrent
=
speed
;
}
public
int
getSpeed
()
{
return
speedCurrent
;
}
public
void
setT
(
float
length
)
{
// 2024_04_16 time (s) = length (m) / speedCurrent (m/s)
this
.
t
=
length
/
speedCurrent
;
}
public
float
getT
()
{
return
this
.
t
;
}
public
float
getWatingTime
()
{
return
watingTime
;
}
public
void
setDeltaT
(
float
positionFront
,
int
speedFront
)
{
//change it because of the gaps that can be broken
if
(
speedFront
<
speedCurrent
)
{
// 2024_04_16 deltaTime (s) = deltaDistance (m) / deltaSpeed (m/s)
this
.
deltaT
=
(
positionFront
-
position
-
DistaceBetweenCar
-
CarLenght
)
/
(
speedCurrent
-
speedFront
);
if
((
positionFront
-
position
-
DistaceBetweenCar
-
CarLenght
)<
0
)
{
this
.
deltaT
=
0
;
this
.
position
=
positionFront
-
DistaceBetweenCar
-
CarLenght
;
}
}
else
this
.
deltaT
=
Float
.
POSITIVE_INFINITY
;
}
public
float
getDeltaT
()
{
return
this
.
deltaT
;
}
public
void
setPosition
()
{
this
.
position
=
0
;
}
public
float
getPosition
()
{
return
this
.
position
;
}
// Update position, t, deltaT when AMRoad has an external event
public
void
updateValue
(
float
e
)
{
// 2024_04_16 position (m) = speed (m/s) * time (s)
this
.
position
+=
speedCurrent
*
e
;
this
.
t
-=
e
;
this
.
deltaT
-=
e
;
}
public
void
updateWatingTime
(
float
e
)
{
this
.
watingTime
-=
e
;
}
// Update speed, t, deltaT when car reaches front car
public
void
updateValue
(
int
speedFront
,
float
timeFront
)
{
this
.
speedCurrent
=
speedFront
;
// why i changed it ?
//this.t=timeFront;
float
gaps
=
(
DistaceBetweenCar
+
CarLenght
)
;
// i diveded float / int to have a float result
this
.
t
=
timeFront
+
(
gaps
/
speedFront
);
this
.
deltaT
=
Float
.
POSITIVE_INFINITY
;
}
// Arrival time is set when car is received at AMTransducer
public
void
setArrivalTime
(
float
time
)
{
arrivalTime
=
time
;
}
public
void
setWatingTime
(
float
PositionFront
,
int
speedFront
)
{
watingTime
=(
5
-
PositionFront
)/(
speedFront
);
}
// Test 2024_04_09
public
void
addSpeed
(
float
time
)
{
listSpeed
.
add
(
String
.
valueOf
(
time
)
+
" "
+
String
.
valueOf
(
speedCurrent
));
}
// Test 2024_04_09
public
void
addPosition
(
float
time
)
{
listPosition
.
add
(
String
.
valueOf
(
time
)
+
" "
+
String
.
valueOf
(
position
));
}
}
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