Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AppAlgo-SoSe24
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
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
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
voic00
AppAlgo-SoSe24
Commits
96a8df6e
Commit
96a8df6e
authored
1 year ago
by
voic00
Browse files
Options
Downloads
Patches
Plain Diff
started implementing logic to add constraints sorted after node degree
parent
08649738
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/main_iterative_opt.py
+25
-5
25 additions, 5 deletions
src/main_iterative_opt.py
with
25 additions
and
5 deletions
src/main_iterative_opt.py
+
25
−
5
View file @
96a8df6e
...
@@ -98,7 +98,7 @@ def add_edge_to_node_dict(dict : dict[int, list[int]], edge : tuple[int, int], m
...
@@ -98,7 +98,7 @@ def add_edge_to_node_dict(dict : dict[int, list[int]], edge : tuple[int, int], m
# Append edge to dictionary of edges
# Append edge to dictionary of edges
dict
[
bNode
].
append
(
aNode
)
dict
[
bNode
].
append
(
aNode
)
def
parse_graph_file
(
graph_file
):
def
parse_graph_file
(
graph_file
:
str
)
->
tuple
[
int
,
int
,
list
[
tuple
[
int
,
int
]]]:
edges
=
[]
edges
=
[]
number_of_nodes_in_A
=
0
number_of_nodes_in_A
=
0
number_of_nodes_in_B
=
0
number_of_nodes_in_B
=
0
...
@@ -111,8 +111,8 @@ def parse_graph_file(graph_file):
...
@@ -111,8 +111,8 @@ def parse_graph_file(graph_file):
number_of_nodes_in_A
=
int
(
parts
[
2
])
number_of_nodes_in_A
=
int
(
parts
[
2
])
number_of_nodes_in_B
=
int
(
parts
[
3
])
number_of_nodes_in_B
=
int
(
parts
[
3
])
else
:
else
:
x
,
positionalVariables
=
map
(
int
,
line
.
split
())
x
,
y
=
map
(
int
,
line
.
split
())
edges
.
append
((
x
,
positionalVariables
))
edges
.
append
((
x
,
y
))
return
number_of_nodes_in_A
,
number_of_nodes_in_B
,
edges
return
number_of_nodes_in_A
,
number_of_nodes_in_B
,
edges
...
@@ -141,7 +141,7 @@ def solve_bipartite_minimization(graph_file):
...
@@ -141,7 +141,7 @@ def solve_bipartite_minimization(graph_file):
nodes_with_degree_higher_one
=
dict
(
filter
(
lambda
keyValuePair
:
len
(
keyValuePair
[
1
])
>
1
,
B_nodes_with_associated_A_nodes
.
items
()))
nodes_with_degree_higher_one
=
dict
(
filter
(
lambda
keyValuePair
:
len
(
keyValuePair
[
1
])
>
1
,
B_nodes_with_associated_A_nodes
.
items
()))
# Erstelle Liste aller Nodes in B mit einem Grad = 1 und
# Erstelle Liste aller Nodes in B mit einem Grad = 1 und
nodes_with_degree_equals_one
=
[(
bNode
,
aNodes
[
0
]
)
for
(
bNode
,
aNodes
)
in
B_nodes_with_associated_A_nodes
.
items
()
if
len
(
aNodes
)
==
1
]
nodes_with_degree_equals_one
=
{
bNode
:
aNodes
[
0
]
for
(
bNode
,
aNodes
)
in
B_nodes_with_associated_A_nodes
.
items
()
if
len
(
aNodes
)
==
1
}
# Sortiere sie nach ihrem korrospondierenden Knoten Wert von A, dann sind alle Knoten in B mit Grad 1 so sortiert, dass ihre Kanten kreuzungsfrei sind
# Sortiere sie nach ihrem korrospondierenden Knoten Wert von A, dann sind alle Knoten in B mit Grad 1 so sortiert, dass ihre Kanten kreuzungsfrei sind
nodes_with_degree_equals_one
.
sort
(
key
=
lambda
node
:
node
[
1
])
nodes_with_degree_equals_one
.
sort
(
key
=
lambda
node
:
node
[
1
])
# Erstelle Liste mit nur den Grad 1 Knoten aus B, erleichtert nachher das Filtern der Edges
# Erstelle Liste mit nur den Grad 1 Knoten aus B, erleichtert nachher das Filtern der Edges
...
@@ -176,6 +176,26 @@ def solve_bipartite_minimization(graph_file):
...
@@ -176,6 +176,26 @@ def solve_bipartite_minimization(graph_file):
# crossingVariablesBetweenMultiAndOne = {}
# crossingVariablesBetweenMultiAndOne = {}
# Variable y(i, j) : Liegt i links von j ? Wenn ja 1, sonst 0.
# Variable y(i, j) : Liegt i links von j ? Wenn ja 1, sonst 0.
positional_vars_without_degree_one_nodes
=
{}
for
nodeX
in
range
(
number_of_nodes_in_A
+
1
,
number_of_nodes_in_A
+
number_of_nodes_in_B
+
1
):
if
not
nodeX
in
nodes_with_degree_equals_one
:
continue
for
nodeY
in
range
(
number_of_nodes_in_A
+
1
,
number_of_nodes_in_A
+
number_of_nodes_in_B
+
1
):
if
not
nodeY
in
nodes_with_degree_equals_one
:
continue
if
i
==
j
:
continue
positional_vars_without_degree_one_nodes
[(
nodeX
,
nodeY
)]
=
LpVariable
(
f
"
y_
{
nodeX
}
_
{
nodeY
}
"
,
0
,
1
,
cat
=
'
Binary
'
)
positional_vars_without_degree_one_nodes
[(
nodeX
,
nodeY
)].
setInitialValue
(
0
)
# Setze die Variablen, der Knoten, die Grad 1 haben so, dass die Ordnung bereits vorgegeben ist (Hoffnung hier ist, dass damit der Solver schon mit einer besseren Lösung anfangen kann, weil er dieses triviale Probem nicht zusätzlich lösen muss)
for
i
in
range
(
len
(
nodes_with_degree_equals_one
)
-
1
):
positional_vars_without_degree_one_nodes
[(
nodes_with_degree_equals_one
[
i
][
0
],
nodes_with_degree_equals_one
[
i
+
1
][
0
])].
setInitialValue
(
1
)
# Erstelle die Crossing constraints für die Kanten, die an Knoten liegen, die Grad = 1 haben
for
(
nodeB
,
nodeA
)
in
nodes_with_degree_equals_one
:
for
(
k
,
l
)
in
edges
:
positionalVariables
=
{(
i
,
j
):
LpVariable
(
f
"
y_
{
i
}
_
{
j
}
"
,
0
,
1
,
cat
=
'
Binary
'
)
for
i
in
range
(
number_of_nodes_in_A
+
1
,
number_of_nodes_in_A
+
number_of_nodes_in_B
+
1
)
for
j
in
range
(
number_of_nodes_in_A
+
1
,
number_of_nodes_in_A
+
number_of_nodes_in_B
+
1
)
if
i
!=
j
}
positionalVariables
=
{(
i
,
j
):
LpVariable
(
f
"
y_
{
i
}
_
{
j
}
"
,
0
,
1
,
cat
=
'
Binary
'
)
for
i
in
range
(
number_of_nodes_in_A
+
1
,
number_of_nodes_in_A
+
number_of_nodes_in_B
+
1
)
for
j
in
range
(
number_of_nodes_in_A
+
1
,
number_of_nodes_in_A
+
number_of_nodes_in_B
+
1
)
if
i
!=
j
}
# Variable c(i,j,k,l) : Kreuzt die Kante zwischen i-j die Kante zwischen k-l
# Variable c(i,j,k,l) : Kreuzt die Kante zwischen i-j die Kante zwischen k-l
crossingVariables
=
{(
i
,
j
,
k
,
l
):
LpVariable
(
f
"
c_
{
i
}
_
{
j
}
_
{
k
}
_
{
l
}
"
,
0
,
1
,
cat
=
'
Binary
'
)
for
(
i
,
j
)
in
edges
for
(
k
,
l
)
in
edges
}
crossingVariables
=
{(
i
,
j
,
k
,
l
):
LpVariable
(
f
"
c_
{
i
}
_
{
j
}
_
{
k
}
_
{
l
}
"
,
0
,
1
,
cat
=
'
Binary
'
)
for
(
i
,
j
)
in
edges
for
(
k
,
l
)
in
edges
}
...
...
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