From 438147693e32e8ac80ff67ebff3097c5a3b24d27 Mon Sep 17 00:00:00 2001 From: Sebastian Buchwald Date: Fri, 3 Oct 2008 10:15:27 +0000 Subject: [PATCH] Finished edge allocation. [r22428] --- matrix.c | 17 +++++++++++++++++ matrix.h | 4 ++++ pbqp_edge.c | 10 +++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/matrix.c b/matrix.c index 029514dda..8356af016 100644 --- a/matrix.c +++ b/matrix.c @@ -19,3 +19,20 @@ matrix *matrix_copy(pbqp *pbqp, matrix *m) return copy; } + +void matrix_add(matrix *sum, matrix *summand) +{ + int i; + int len; + + assert(sum); + assert(summand); + assert(sum->cols == summand->cols); + assert(sum->rows == summand->rows); + + len = sum->rows * sum->cols; + + for (i = 0; i < len; ++i) { + sum->entries[i] += summand->entries[i]; + } +} diff --git a/matrix.h b/matrix.h index 4e2351d49..6b5360d65 100644 --- a/matrix.h +++ b/matrix.h @@ -3,6 +3,10 @@ #include "matrix_t.h" +/* Copy the given matrix. */ matrix *matrix_copy(pbqp *pbqp, matrix *m); +/* sum += summand */ +void matrix_add(matrix *sum, matrix *summand); + #endif /* KAPS_MATRIX_H */ diff --git a/pbqp_edge.c b/pbqp_edge.c index 6218306f2..e59b7e825 100644 --- a/pbqp_edge.c +++ b/pbqp_edge.c @@ -1,3 +1,4 @@ +#include "adt/array.h" #include "assert.h" #include "kaps.h" @@ -27,7 +28,14 @@ pbqp_edge *alloc_edge(pbqp *pbqp, int src_index, int tgt_index, matrix *costs) edge->costs = matrix_copy(pbqp, costs); - // TODO: connect edge with nodes + /* + * Connect edge with incident nodes. Since the edge is allocated, we know + * that it don't appear in the edge lists of the nodes. + */ + ARR_APP1(pbqp_edge *, src_node->edges, edge); + edge->src = src_node; + ARR_APP1(pbqp_edge *, tgt_node->edges, edge); + edge->tgt = tgt_node; return edge; } -- 2.20.1