Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
A Generic Flexible Protocol for Neighbor Discovery
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
Anastasiia Chirikova
A Generic Flexible Protocol for Neighbor Discovery
Commits
4dab4d24
Commit
4dab4d24
authored
11 months ago
by
achirikova
Browse files
Options
Downloads
Patches
Plain Diff
[3] input
parent
e83296cf
No related branches found
No related tags found
1 merge request
!3
[3] input
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ndp/main.py
+18
-11
18 additions, 11 deletions
ndp/main.py
with
18 additions
and
11 deletions
ndp/main.py
+
18
−
11
View file @
4dab4d24
import
matplotlib.pyplot
as
plt
import
numpy
as
np
class
Protocol
:
def
__init__
(
self
,
name
,
c
,
n
):
self
.
name
=
name
...
...
@@ -19,11 +18,11 @@ class Protocol:
slots
=
np
.
zeros
(
total_slots
)
for
g
in
guardians
:
slots
[
g
]
=
1
# Guardian slots
slots
[
g
%
total_slots
]
=
1
# Guardian slots
for
p
in
patrols
:
if
slots
[
p
]
==
0
:
# Only mark patrol if not already a guardian
slots
[
p
]
=
2
# Patrol slots
if
slots
[
p
%
total_slots
]
==
0
:
# Only mark patrol if not already a guardian
slots
[
p
%
total_slots
]
=
2
# Patrol slots
slots
=
slots
.
reshape
(
self
.
n
,
self
.
c
)
...
...
@@ -35,15 +34,19 @@ class Protocol:
class
QuorumProtocol
(
Protocol
):
def
schedule
(
self
):
guardians
=
[
i
*
self
.
c
for
i
in
range
(
self
.
n
)]
guardians
=
[
i
%
self
.
c
for
i
in
range
(
self
.
n
)]
patrols
=
[
i
for
i
in
range
(
self
.
c
)
if
i
not
in
guardians
]
return
{
"
Guardians
"
:
guardians
,
"
Patrols
"
:
patrols
}
class
DiscoProtocol
(
Protocol
):
def
schedule
(
self
):
# Generate guardians based on the formula i * c
guardians
=
[
i
*
self
.
c
for
i
in
range
(
self
.
n
)]
# Generate patrols based on the formula j * n, excluding guardians
patrols
=
[
j
*
self
.
n
for
j
in
range
(
self
.
c
)
if
j
*
self
.
n
not
in
guardians
]
return
{
"
Guardians
"
:
guardians
,
"
Patrols
"
:
patrols
}
...
...
@@ -57,20 +60,24 @@ class UConnectProtocol(Protocol):
class
SearchlightProtocol
(
Protocol
):
def
schedule
(
self
):
guardians
=
[
i
*
self
.
c
for
i
in
range
(
self
.
n
)]
patrols
=
[(
j
*
self
.
c
+
(
j
%
(
self
.
c
//
2
)))
for
j
in
range
(
self
.
n
)
if
patrols
=
[(
j
*
self
.
c
+
(
j
%
(
self
.
c
//
2
)))
for
j
in
range
(
self
.
n
*
2
)
if
(
j
*
self
.
c
+
(
j
%
(
self
.
c
//
2
)))
not
in
guardians
]
return
{
"
Guardians
"
:
guardians
,
"
Patrols
"
:
patrols
}
return
{
"
Guardians
"
:
guardians
,
"
Patrols
"
:
patrols
[:
self
.
n
]}
# Get user input for c and n
c
=
int
(
input
(
"
Enter the number of slots per cycle (c):
"
))
n
=
int
(
input
(
"
Enter the number of cycles (n):
"
))
# Plot all protocols
fig
,
axes
=
plt
.
subplots
(
4
,
1
,
figsize
=
(
12
,
20
),
sharex
=
True
)
fig
.
subplots_adjust
(
hspace
=
0.4
)
protocols
=
[
QuorumProtocol
(
"
Quorum Protocol
"
,
9
,
3
),
DiscoProtocol
(
"
Disco Protocol
"
,
7
,
5
),
UConnectProtocol
(
"
U-Connect Protocol
"
,
7
,
7
),
SearchlightProtocol
(
"
Searchlight Protocol
"
,
7
,
3
)
QuorumProtocol
(
"
Quorum Protocol
"
,
c
,
n
),
DiscoProtocol
(
"
Disco Protocol
"
,
c
,
n
),
UConnectProtocol
(
"
U-Connect Protocol
"
,
c
,
n
),
SearchlightProtocol
(
"
Searchlight Protocol
"
,
c
,
n
)
]
for
i
,
protocol
in
enumerate
(
protocols
):
...
...
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