Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
unix
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
tu-wien
unix
Commits
696deabb
Commit
696deabb
authored
Jan 13, 2019
by
Ivaylo Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add generator functionality
parent
4887235d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
5 deletions
+32
-5
fb_arc_set/generator.c
fb_arc_set/generator.c
+31
-5
fb_arc_set/supervisor.c
fb_arc_set/supervisor.c
+1
-0
No files found.
fb_arc_set/generator.c
View file @
696deabb
...
@@ -81,7 +81,7 @@ int main(int argc, char *argv[]) {
...
@@ -81,7 +81,7 @@ int main(int argc, char *argv[]) {
}
}
num_nodes
++
;
///< Our first node is labeled 0, so we need to add 1 more
num_nodes
++
;
///< Our first node is labeled 0, so we need to add 1 more
/// Declare array
s
for unique nodes
/// Declare array for unique nodes
int
unique_nodes
[
num_nodes
];
int
unique_nodes
[
num_nodes
];
/// Filling the node array with the nodes
/// Filling the node array with the nodes
...
@@ -101,9 +101,9 @@ int main(int argc, char *argv[]) {
...
@@ -101,9 +101,9 @@ int main(int argc, char *argv[]) {
/// Declaring buffer arrays and variables
/// Declaring buffer arrays and variables
int
current_best
=
num_edges
-
1
;
///< Set a basic best solution
int
current_best
=
num_edges
-
1
;
///< Set a basic best solution
int
new_best
=
0
;
int
buf_nodes
[
num_nodes
];
int
buf_nodes
[
num_nodes
];
edge_t
buf_edges
[
num_edges
];
edge_t
buf_edges
[
num_edges
];
int
new_best
=
0
;
while
(
terminate
!=
true
&&
circ_buffer
->
finished
!=
true
)
{
///< Loop until told to stop or until an acyclic solution is discovered
while
(
terminate
!=
true
&&
circ_buffer
->
finished
!=
true
)
{
///< Loop until told to stop or until an acyclic solution is discovered
/// Copy the original into a buffer array and shuffle it
/// Copy the original into a buffer array and shuffle it
...
@@ -113,7 +113,7 @@ int main(int argc, char *argv[]) {
...
@@ -113,7 +113,7 @@ int main(int argc, char *argv[]) {
/// Reset the chosen status of the edges
/// Reset the chosen status of the edges
memcpy
(
buf_edges
,
edges
,
sizeof
(
edges
));
memcpy
(
buf_edges
,
edges
,
sizeof
(
edges
));
new_best
=
0
;
///< Reset the new_bes
y
counter
new_best
=
0
;
///< Reset the new_bes
t
counter
for
(
int
i
=
0
;
i
<
num_edges
;
i
++
)
{
for
(
int
i
=
0
;
i
<
num_edges
;
i
++
)
{
if
(
new_best
>=
SET_MAX_SIZE
||
new_best
>=
num_edges
)
if
(
new_best
>=
SET_MAX_SIZE
||
new_best
>=
num_edges
)
break
;
///< Skip if the solution is faulty
break
;
///< Skip if the solution is faulty
...
@@ -130,11 +130,37 @@ int main(int argc, char *argv[]) {
...
@@ -130,11 +130,37 @@ int main(int argc, char *argv[]) {
}
}
/// Construct the new feedback arc set
/// Construct the new feedback arc set
if
(
new_best
<
current_best
&&
new_best
<=
SET_MAX_SIZE
)
{
if
(
new_best
<
current_best
&&
new_best
<=
SET_MAX_SIZE
&&
current_best
<
circ_buffer
->
best_arc_len
)
{
current_best
=
new_best
;
current_best
=
new_best
;
fb_arc_set_t
res
;
memset
(
&
res
,
0
,
sizeof
(
struct
fb_arc_set
));
/// Removes faulty data from the buffer later
for
(
int
i
=
0
;
i
<
num_edges
;
i
++
)
{
if
(
buf_edges
[
i
].
chosen
==
true
)
{
res
.
edge_num
++
;
res
.
edges
[
--
new_best
]
=
edges
[
i
];
///< We begin counting from 0
}
}
res
.
valid
=
true
;
wait_sem
(
mutex
);
///< Say that it's our turn to write
wait_sem
(
free_sem
);
///< Lock the free space semaphore
/// Find a free space to write to
while
(
circ_buffer
->
sets
[
wr_pos
].
valid
==
true
)
{
wr_pos
=
(
wr_pos
+
1
)
%
BUFF_SIZE
;
}
circ_buffer
->
sets
[
wr_pos
]
=
res
;
post_sem
(
use_sem
);
wr_pos
=
(
wr_pos
+
1
)
%
BUFF_SIZE
;
post_sem
(
mutex
);
if
(
current_best
==
0
)
{
signal_handler
(
15
);
}
}
}
}
}
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
}
}
...
...
fb_arc_set/supervisor.c
View file @
696deabb
...
@@ -79,6 +79,7 @@ int main(int argc, char *argv[]) {
...
@@ -79,6 +79,7 @@ int main(int argc, char *argv[]) {
if
(
fb_arc
.
edge_num
==
0
)
{
if
(
fb_arc
.
edge_num
==
0
)
{
/// If the graph is acyclic, set the terminate flag
/// If the graph is acyclic, set the terminate flag
puts
(
"The graph is acyclic!"
);
puts
(
"The graph is acyclic!"
);
circ_buffer
->
finished
=
true
;
signal_handler
(
SIGINT
);
signal_handler
(
SIGINT
);
}
else
if
(
fb_arc
.
edge_num
<
circ_buffer
->
best_arc_len
)
{
}
else
if
(
fb_arc
.
edge_num
<
circ_buffer
->
best_arc_len
)
{
/// Save ther best feedback arc length and print a solution
/// Save ther best feedback arc length and print a solution
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment