Add generator functionality
This commit is contained in:
parent
4887235d61
commit
696deabb91
@ -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 arrays 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[]) {
|
|||||||
|
|
||||||
/// 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[]) {
|
|||||||
/// 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_besy counter
|
new_best = 0; ///< Reset the new_best 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[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
Reference in New Issue
Block a user