Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
B4M33PAL
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
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
Filip Štěpánek
B4M33PAL
Commits
428f1706
Commit
428f1706
authored
3 years ago
by
Filip Štěpánek
Browse files
Options
Downloads
Patches
Plain Diff
Working but wrong algo lol
parent
6a69350f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
2Conveyor/datapub/vis.py
+37
-0
37 additions, 0 deletions
2Conveyor/datapub/vis.py
2Conveyor/main.cpp
+43
-17
43 additions, 17 deletions
2Conveyor/main.cpp
with
80 additions
and
17 deletions
2Conveyor/datapub/vis.py
0 → 100644
+
37
−
0
View file @
428f1706
import
networkx
as
nx
import
matplotlib.pyplot
as
plt
file1
=
open
(
'
pub03.in
'
,
'
r
'
)
headerline
=
file1
.
readline
()
print
(
headerline
)
header
=
headerline
.
split
()
factoryCount
=
int
(
header
[
0
])
convCount
=
int
(
header
[
1
])
mainFactory
=
int
(
header
[
2
])
G
=
nx
.
DiGraph
()
for
i
in
range
(
factoryCount
):
G
.
add_node
(
i
)
edges
=
[]
for
i
in
range
(
convCount
):
edgeText
=
headerline
=
file1
.
readline
()
edge
=
edgeText
.
split
()
G
.
add_edge
(
int
(
edge
[
0
]),
int
(
edge
[
1
]))
G
.
add_edges_from
(
edges
)
pos
=
nx
.
spring_layout
(
G
,
iterations
=
20
,
seed
=
39775
)
nx
.
draw
(
G
,
pos
=
pos
,
with_labels
=
True
,
font_weight
=
'
bold
'
,
node_size
=
factoryCount
)
labels
=
nx
.
get_edge_attributes
(
G
,
'
weight
'
)
nx
.
draw_networkx_edge_labels
(
G
,
pos
,
edge_labels
=
labels
)
#nx.draw(G.subgraph(mainFactory), pos=pos, node_color='red', font_color='green')
plt
.
show
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
2Conveyor/main.cpp
+
43
−
17
View file @
428f1706
...
...
@@ -9,8 +9,10 @@ struct Cluster;
struct
Node
{
int
index
;
std
::
list
<
Node
*>
neighbors
;
std
::
list
<
Node
*>
invertedNeighbors
;
std
::
list
<
Node
*>
directNeighbors
;
int
distance
=
INT_MAX
;
int
reconfigurations
=
INT_MAX
;
int
depth
=
0
;
bool
visited
=
false
;
Node
*
predecesor
=
nullptr
;
Cluster
*
cluster
=
nullptr
;
...
...
@@ -26,7 +28,7 @@ struct Cluster {
class
MyCompare
{
public:
bool
operator
()(
Node
*
a
,
Node
*
b
)
{
return
(
a
->
distance
)
>
(
b
->
distance
);
return
(
a
->
reconfigurations
)
>
(
b
->
reconfigurations
);
}
};
...
...
@@ -62,6 +64,7 @@ int main() {
graph
[
source
].
neighbors
.
push_back
(
&
graph
[
dest
]);
graph
[
dest
].
invertedNeighbors
.
push_back
(
&
graph
[
source
]);
graph
[
source
].
directNeighbors
.
push_back
(
&
graph
[
dest
]);
graph
[
dest
].
directNeighbors
.
push_back
(
&
graph
[
source
]);
...
...
@@ -72,7 +75,13 @@ int main() {
Kosarajus
();
clusters
.
sort
([](
const
Cluster
&
a
,
const
Cluster
&
b
)
->
bool
{
return
a
.
distance
>
b
.
distance
;
if
(
a
.
nearestFactory
->
depth
>
b
.
nearestFactory
->
depth
)
return
true
;
if
(
b
.
nearestFactory
->
depth
>
a
.
nearestFactory
->
depth
)
return
false
;
if
(
a
.
nearestFactory
->
reconfigurations
>
b
.
nearestFactory
->
reconfigurations
)
return
true
;
if
(
b
.
nearestFactory
->
reconfigurations
>
a
.
nearestFactory
->
reconfigurations
)
return
false
;
return
false
;
});
int
re
=
0
;
...
...
@@ -83,9 +92,12 @@ int main() {
Cluster
*
cluster
=
&
(
*
it
);
do
{
Node
*
me
=
cluster
->
nearestFactory
;
Node
*
me
=
cluster
->
nearestFactory
;
while
(
me
->
predecesor
!=
nullptr
)
{
Node
*
predecesor
=
me
->
predecesor
;
me
->
cluster
->
visited
=
true
;
if
(
std
::
find
(
predecesor
->
neighbors
.
begin
(),
predecesor
->
neighbors
.
end
(),
me
)
!=
predecesor
->
neighbors
.
end
())
{
...
...
@@ -97,9 +109,9 @@ int main() {
};
cluster
->
visited
=
true
;
cluster
=
predecesor
->
cluster
;
}
while
(
cluster
->
nearestFactory
->
predecesor
!=
nullptr
);
me
=
predecesor
;
}
}
std
::
cout
<<
re
<<
std
::
endl
;
...
...
@@ -189,8 +201,8 @@ void DFSUtil(Node *v, Cluster *pCluster) {
pCluster
->
nodes
.
push_back
(
v
);
v
->
cluster
=
pCluster
;
if
(
pCluster
->
distance
>
v
->
distance
)
{
pCluster
->
distance
=
v
->
distance
;
if
(
pCluster
->
distance
>
v
->
reconfigurations
)
{
pCluster
->
distance
=
v
->
reconfigurations
;
pCluster
->
nearestFactory
=
v
;
}
...
...
@@ -232,12 +244,11 @@ void BFS(Node *src) {
// Create a queue for BFS
std
::
list
<
Node
*>
queue
;
std
::
list
<
int
>
levelQueue
;
// Mark the current node as visited and enqueue it
src
->
visited
=
true
;
src
->
reconfigurations
=
0
;
queue
.
push_back
(
src
);
levelQueue
.
push_back
(
0
);
// 'i' will be used to get all adjacent
// vertices of a vertex
...
...
@@ -247,20 +258,35 @@ void BFS(Node *src) {
while
(
!
queue
.
empty
())
{
// Dequeue a vertex from queue and print it
src
=
queue
.
front
();
src
->
distance
=
levelQueue
.
front
();
std
::
cout
<<
src
->
index
<<
"-"
<<
src
->
distance
<<
std
::
endl
;
std
::
cout
<<
src
->
index
<<
"-"
<<
src
->
reconfigurations
<<
std
::
endl
;
queue
.
pop_front
();
levelQueue
.
pop_front
();
// Get all adjacent vertices of the dequeued
// vertex s. If a adjacent has not been visited,
// then mark it visited and enqueue it
for
(
i
=
src
->
directNeighbors
.
begin
();
i
!=
src
->
directNeighbors
.
end
();
++
i
)
{
for
(
i
=
src
->
neighbors
.
begin
();
i
!=
src
->
neighbors
.
end
();
++
i
)
{
if
(
!
(
*
i
)
->
visited
)
{
(
*
i
)
->
visited
=
true
;
(
*
i
)
->
predecesor
=
src
;
(
*
i
)
->
reconfigurations
=
src
->
reconfigurations
;
(
*
i
)
->
depth
=
src
->
depth
+
1
;
queue
.
push_back
(
*
i
);
}
else
if
((
*
i
)
->
reconfigurations
>
src
->
reconfigurations
)
{
(
*
i
)
->
predecesor
=
src
;
(
*
i
)
->
reconfigurations
=
src
->
reconfigurations
;
}
}
for
(
i
=
src
->
invertedNeighbors
.
begin
();
i
!=
src
->
invertedNeighbors
.
end
();
++
i
)
{
if
(
!
(
*
i
)
->
visited
)
{
(
*
i
)
->
visited
=
true
;
(
*
i
)
->
predecesor
=
src
;
(
*
i
)
->
reconfigurations
=
src
->
reconfigurations
+
1
;
(
*
i
)
->
depth
=
src
->
depth
+
1
;
queue
.
push_back
(
*
i
);
levelQueue
.
push_back
(
level
);
}
else
if
((
*
i
)
->
reconfigurations
>
src
->
reconfigurations
+
1
)
{
(
*
i
)
->
predecesor
=
src
;
(
*
i
)
->
reconfigurations
=
src
->
reconfigurations
+
1
;
}
}
level
++
;
...
...
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