1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
|
/*
* c_graphmatrix.c - Graph as adjacency matrix
*
* Copyright (C) 2014 Tobias Boege <tobias@gambas-buch.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#define __C_GRAPHMATRIX_C
#include <assert.h>
#include "gambas.h"
#include "c_graph.h"
#include "c_graphmatrix.h"
#define E_NOVERTEX "Vertex does not exist"
#define E_NOEDGE "Edge does not exist"
#define E_NOPUT "No suitable _put method in the Matrix class"
typedef struct {
int set : 1;
double weight;
} EDGE;
/*
* The VERT structure is a row in the adjacency matrix.
*/
typedef struct {
EDGE *edges;
GB_VARIANT_VALUE val;
char *name;
} VERT;
/* Virtual object selector or part of enumeration state */
union virt {
unsigned int vertex;
struct {
unsigned int src, dst;
};
};
typedef struct {
CGRAPH base;
int directed : 1;
int weighted : 1;
GB_HASHTABLE names;
VERT *matrix;
/*
* NOTE: This field is used by the "true" virtual object portions of
* this class: GraphMatrix.Vertices[x] and GraphMatrix.Edges[x, y].
*
* In the enumerators (InEdges, OutEdges, Adjacent), we must use the
* "current" vertex/edge which is stored within ->base.
*/
union virt v;
void *gsl_matrix; /* Cache gb.gsl Matrix object of this */
} CMATRIX;
#define THIS ((CMATRIX *) _object)
BEGIN_METHOD(Matrix_new, GB_BOOLEAN d; GB_BOOLEAN w)
THIS->directed = VARGOPT(d, 0);
THIS->weighted = VARGOPT(w, 0);
THIS->v.vertex = -1;
THIS->v.src = THIS->v.dst = -1;
GB.HashTable.New(&THIS->names, GB_COMP_NOCASE);
GB.NewArray(&THIS->matrix, sizeof(*THIS->matrix), 0);
THIS->gsl_matrix = NULL;
END_METHOD
BEGIN_METHOD_VOID(Matrix_free)
unsigned int i, count = GB.Count(THIS->matrix);
GB.HashTable.Free(&THIS->names);
for (i = 0; i < count; i++) {
VERT *cur = &THIS->matrix[i];
GB.FreeString(&cur->name);
GB.FreeArray(&cur->edges);
GB.StoreVariant(NULL, &cur->val);
}
GB.FreeArray(&THIS->matrix);
GB.Unref(&THIS->gsl_matrix);
END_METHOD
static unsigned int get_vertex(CMATRIX *mat, const char *str, size_t len)
{
uintptr_t vert; /* Be wide enough to get a void *! */
if (GB.HashTable.Get(mat->names, str, len, (void **) &vert))
return -1;
assert(vert >= 0 && vert < GB.Count(mat->matrix));
return (unsigned int) vert;
}
static unsigned int get_cur_vertex(CMATRIX *mat)
{
return get_vertex(mat, mat->base.vertex,
GB.StringLength(mat->base.vertex));
}
BEGIN_METHOD(Matrix_getVertex, GB_STRING vert)
unsigned int vert = get_vertex(THIS, STRING(vert), LENGTH(vert));
if (vert == -1) {
GB.Error(E_NOVERTEX);
return;
}
THIS->v.vertex = vert;
GB.ReturnSelf(THIS);
END_METHOD
BEGIN_METHOD(Matrix_getEdge, GB_STRING src; GB_STRING dst)
unsigned int src = get_vertex(THIS, STRING(src), LENGTH(src)),
dst = get_vertex(THIS, STRING(dst), LENGTH(dst));
if (src == -1 || dst == -1) {
GB.Error(E_NOVERTEX);
return;
}
if (!THIS->matrix[src].edges[dst].set) {
GB.Error(E_NOEDGE);
return;
}
THIS->v.src = src; THIS->v.dst = dst;
GB.ReturnSelf(THIS);
END_METHOD
struct enum_state {
union virt v;
GB_ARRAY e;
};
BEGIN_METHOD_VOID(Matrix_nextVertex)
struct enum_state *state = GB.GetEnum();
if (state->v.vertex == GB.Count(THIS->matrix)) {
GB.StopEnum();
return;
}
GB.ReturnString(THIS->matrix[state->v.vertex++].name);
END_METHOD
/* Return non-zero if no next edge was found */
static int next_edge(CMATRIX *mat, unsigned int *srcp, unsigned int *dstp)
{
unsigned int src = *srcp, dst = *dstp;
unsigned int count = GB.Count(mat->matrix);
do {
dst = (dst + 1) % count;
if (!dst)
src++;
if (src >= count)
return -1;
} while (!mat->matrix[src].edges[dst].set);
*srcp = src;
*dstp = dst;
return 0;
}
/**G
* The same String[] object is used during the enumeration. If you want to
* save a snapshot of it, use String[].Copy().
*
* Also, you should maybe not change the contents of this array. It may work
* now but I can't guarantee it will in the future.
*/
BEGIN_METHOD_VOID(Matrix_nextEdge)
struct enum_state *state = GB.GetEnum();
unsigned int src = state->v.src, dst = state->v.dst;
if (!state->e) {
GB.Array.New(&state->e, GB_T_STRING, 2);
GB.Ref(state->e);
/* Try edge 0,0 which is a special case according to the
* logic below. */
if (THIS->matrix[src].edges[dst].set)
goto found;
}
/* End of enumeration? */
if (next_edge(THIS, &src, &dst)) {
GB.StopEnum();
GB.Unref(&state->e);
return;
}
state->v.src = src; state->v.dst = dst;
found:;
GB_STRING str;
str.type = GB_T_STRING;
str.value.addr = THIS->matrix[src].name;
str.value.start = 0;
str.value.len = GB.StringLength(str.value.addr);
GB.StoreString(&str, GB.Array.Get(state->e, 0));
str.value.addr = THIS->matrix[dst].name;
str.value.len = GB.StringLength(str.value.addr);
GB.StoreString(&str, GB.Array.Get(state->e, 1));
GB.ReturnObject(state->e);
END_METHOD
BEGIN_METHOD_VOID(Matrix_countVertices)
GB.ReturnInteger(GB.Count(THIS->matrix));
END_METHOD
BEGIN_METHOD_VOID(Matrix_countEdges)
unsigned int i, j, count = GB.Count(THIS->matrix), edges = 0;
for (i = 0; i < count; i++)
for (j = 0; j < count; j++)
if (THIS->matrix[i].edges[j].set)
edges++;
GB.ReturnInteger(edges);
END_METHOD
static int next_edge_vertical(CMATRIX *mat, unsigned int *srcp,
unsigned int *dstp)
{
unsigned int src = *srcp, dst = *dstp;
unsigned int count = GB.Count(mat->matrix);
do {
src = (src + 1) % count;
if (!src)
dst++;
if (dst >= count)
return -1;
} while (!mat->matrix[src].edges[dst].set);
*srcp = src;
*dstp = dst;
return 0;
}
BEGIN_METHOD_VOID(Matrix_nextInEdge)
struct enum_state *state = GB.GetEnum();
unsigned int src = state->v.src, dst = state->v.dst;
if (!state->e) {
dst = state->v.dst = get_cur_vertex(THIS);
GB.Array.New(&state->e, GB_T_STRING, 2);
GB.Ref(state->e);
if (THIS->matrix[src].edges[dst].set)
goto found;
}
if (next_edge_vertical(THIS, &src, &dst) || dst != state->v.dst) {
GB.StopEnum();
GB.Unref(&state->e);
return;
}
state->v.src = src;
found:;
GB_STRING str;
str.type = GB_T_STRING;
str.value.addr = THIS->matrix[src].name;
str.value.start = 0;
str.value.len = GB.StringLength(str.value.addr);
GB.StoreString(&str, GB.Array.Get(state->e, 0));
str.value.addr = THIS->matrix[dst].name;
str.value.len = GB.StringLength(str.value.addr);
GB.StoreString(&str, GB.Array.Get(state->e, 1));
GB.ReturnObject(state->e);
END_METHOD
BEGIN_METHOD_VOID(Matrix_nextOutEdge)
struct enum_state *state = GB.GetEnum();
unsigned int src = state->v.src, dst = state->v.dst;
if (!state->e) {
src = state->v.src = get_cur_vertex(THIS);
GB.Array.New(&state->e, GB_T_STRING, 2);
GB.Ref(state->e);
if (THIS->matrix[src].edges[dst].set)
goto found;
}
if (next_edge(THIS, &src, &dst) || src != state->v.src) {
GB.StopEnum();
GB.Unref(&state->e);
return;
}
state->v.dst = dst;
found:;
GB_STRING str;
str.type = GB_T_STRING;
str.value.addr = THIS->matrix[src].name;
str.value.start = 0;
str.value.len = GB.StringLength(str.value.addr);
GB.StoreString(&str, GB.Array.Get(state->e, 0));
str.value.addr = THIS->matrix[dst].name;
str.value.len = GB.StringLength(str.value.addr);
GB.StoreString(&str, GB.Array.Get(state->e, 1));
GB.ReturnObject(state->e);
END_METHOD
BEGIN_METHOD_VOID(Matrix_nextAdjacent)
struct enum_state *state = GB.GetEnum();
unsigned int src = state->v.src, dst = state->v.dst;
if (!state->e) {
src = state->v.src = get_cur_vertex(THIS);
state->e = (void *) 1;
if (THIS->matrix[src].edges[dst].set)
goto found;
}
if (next_edge(THIS, &src, &dst) || src != state->v.src) {
GB.StopEnum();
return;
}
state->v.dst = dst;
found:
GB.ReturnString(THIS->matrix[dst].name);
END_METHOD
/* TODO: This is used in Add() and Remove() to completely delete the gb.gsl
* matrix. We could also enlarge/shrink it accordingly... */
static void invalidate_gsl_matrix(CMATRIX *mat)
{
GB.Unref(&mat->gsl_matrix);
mat->gsl_matrix = NULL;
}
static void update_gsl_matrix(CMATRIX *mat, unsigned i, unsigned j)
{
GB_FUNCTION put;
if (!mat->gsl_matrix)
return;
if (GB.GetFunction(&put, mat->gsl_matrix, "_put", "vii", NULL)) {
GB.Error(E_NOPUT);
return;
}
GB.Push(3, GB_T_INTEGER, !!mat->matrix[i].edges[j].set,
GB_T_INTEGER, i,
GB_T_INTEGER, j);
GB.Call(&put, 3, 0);
}
BEGIN_METHOD(Matrix_Add, GB_STRING name)
unsigned int vert = get_vertex(THIS, STRING(name), LENGTH(name)), i;
VERT *new;
if (vert != -1)
goto end;
vert = GB.Count(THIS->matrix);
new = GB.Add(&THIS->matrix);
/* Add edge buffers to all other vertices */
for (i = 0; i < vert; i++) {
EDGE *e = GB.Add(&THIS->matrix[i].edges);
e->set = 0;
e->weight = 0;
}
GB.NewArray(&new->edges, sizeof(*new->edges), vert + 1);
/* No outgoing edges */
memset(new->edges, 0, (vert + 1) * sizeof(*new->edges));
new->val.type = GB_T_NULL;
GB.StoreVariant(NULL, &new->val);
new->name = GB.NewString(STRING(name), LENGTH(name));
GB.HashTable.Add(THIS->names, STRING(name), LENGTH(name),
(void *) (intptr_t) vert);
invalidate_gsl_matrix(THIS);
end:
THIS->v.vertex = vert;
GB.ReturnSelf(THIS);
END_METHOD
BEGIN_METHOD(Matrix_Remove, GB_STRING vert)
unsigned int vert = get_vertex(THIS, STRING(vert), LENGTH(vert));
unsigned int count = GB.Count(THIS->matrix), i;
if (vert == -1) {
GB.Error(E_NOVERTEX);
return;
}
for (i = 0; i < count; i++) {
if (i == vert)
continue;
GB.Remove(&THIS->matrix[i].edges, i, 1);
}
GB.FreeArray(&THIS->matrix[vert].edges);
GB.StoreVariant(NULL, &THIS->matrix[vert].val);
GB.FreeString(&THIS->matrix[vert].name);
GB.Remove(&THIS->matrix, vert, 1);
GB.HashTable.Remove(THIS->names, STRING(vert), LENGTH(vert));
invalidate_gsl_matrix(THIS);
END_METHOD
BEGIN_METHOD(Matrix_Connect, GB_STRING src; GB_STRING dst; GB_FLOAT w)
unsigned int src = get_vertex(THIS, STRING(src), LENGTH(src)),
dst = get_vertex(THIS, STRING(dst), LENGTH(dst));
float w = VARGOPT(w, 1);
if (src == -1 || dst == -1) {
GB.Error(E_NOVERTEX);
return;
}
THIS->matrix[src].edges[dst].set = 1;
THIS->matrix[src].edges[dst].weight = w;
THIS->v.src = src; THIS->v.dst = dst;
update_gsl_matrix(THIS, src, dst);
/* Duplicate if the graph is undirected */
if (!THIS->directed && src != dst) {
THIS->matrix[dst].edges[src].set = 1;
THIS->matrix[dst].edges[src].weight = w;
update_gsl_matrix(THIS, dst, src);
}
GB.ReturnSelf(THIS);
END_METHOD
BEGIN_METHOD(Matrix_Disconnect, GB_STRING src; GB_STRING dst)
unsigned int src = get_vertex(THIS, STRING(src), LENGTH(src)),
dst = get_vertex(THIS, STRING(dst), LENGTH(dst));
if (src == -1 || dst == -1) {
GB.Error(E_NOVERTEX);
return;
}
THIS->matrix[src].edges[dst].set = 0;
update_gsl_matrix(THIS, src, dst);
if (!THIS->directed && src != dst) {
THIS->matrix[dst].edges[src].set = 0;
update_gsl_matrix(THIS, dst, src);
}
END_METHOD
BEGIN_PROPERTY(Matrix_Matrix)
unsigned int count = GB.Count(THIS->matrix), i, j;
void *obj;
GB_FUNCTION put;
if (THIS->gsl_matrix) {
GB.ReturnObject(THIS->gsl_matrix);
return;
}
if (GB.Component.Load("gb.gsl")) {
GB.Error("gb.gsl could not be found");
return;
}
GB.Push(3, GB_T_INTEGER, count,
GB_T_INTEGER, count,
GB_T_BOOLEAN, 0);
obj = GB.New(GB.FindClass("Matrix"), NULL, (void *) (intptr_t) 3);
if (GB.GetFunction(&put, obj, "_put", "vii", NULL)) {
GB.Error(E_NOPUT);
return;
}
/* TODO: Direct access possible? */
for (i = 0; i < count; i++) {
for (j = 0; j < count; j++) {
GB.Push(3, GB_T_INTEGER,
!!THIS->matrix[i].edges[j].set,
GB_T_INTEGER, i,
GB_T_INTEGER, j);
GB.Call(&put, 3, 0);
}
}
THIS->gsl_matrix = obj;
GB.Ref(obj);
GB.ReturnObject(obj);
END_PROPERTY
GB_DESC CGraphMatrix[] = {
GB_DECLARE("GraphMatrix", sizeof(CMATRIX)),
GB_INHERITS("Graph"),
GB_METHOD("_new", NULL, Matrix_new, "[(Directed)b(Weighted)b]"),
GB_METHOD("_free", NULL, Matrix_free, NULL),
GB_METHOD("_getVertex", ".Matrix.Vertex", Matrix_getVertex, "(Vertex)s"),
GB_METHOD("_getEdge", ".Matrix.Edge", Matrix_getEdge, "(Src)s(Dst)s"),
GB_METHOD("_nextVertex", "s", Matrix_nextVertex, NULL),
GB_METHOD("_nextEdge", "String[]", Matrix_nextEdge, NULL),
GB_METHOD("_countVertices", "i", Matrix_countVertices, NULL),
GB_METHOD("_countEdges", "i", Matrix_countEdges, NULL),
GB_METHOD("_nextInEdge", "String[]", Matrix_nextInEdge, NULL),
GB_METHOD("_nextOutEdge", "String[]", Matrix_nextOutEdge, NULL),
GB_METHOD("_nextAdjacent", "s", Matrix_nextAdjacent, NULL),
GB_METHOD("Add", ".Matrix.Vertex", Matrix_Add, "(Name)s"),
GB_METHOD("Remove", NULL, Matrix_Remove, "(Vertex)s"),
GB_METHOD("Connect", ".Matrix.Edge", Matrix_Connect, "(Src)s(Dst)s[(Weight)f]"),
GB_METHOD("Disconnect", NULL, Matrix_Disconnect, "(Src)s(Dst)s"),
GB_PROPERTY_SELF("Vertices", ".Matrix.Vertices"),
GB_PROPERTY_SELF("Edges", ".Matrix.Edges"),
/*
* Require gb.gsl.
*/
//GB_STATIC_METHOD("FromMatrix", "GraphMatrix", Matrix_FromMatrix, "(Matrix)Matrix;"),
GB_PROPERTY_READ("Matrix", "Matrix", Matrix_Matrix),
GB_END_DECLARE
};
BEGIN_METHOD(MatrixVertices_get, GB_STRING vert)
THIS->v.vertex = get_vertex(THIS, STRING(vert), LENGTH(vert));
GB.ReturnSelf(THIS);
END_METHOD
GB_DESC CMatrixVertices[] = {
GB_DECLARE_VIRTUAL(".Matrix.Vertices"),
GB_INHERITS(".Graph.Vertices"),
GB_METHOD("_get", ".Matrix.Vertex", MatrixVertices_get, "(Vertex)s"),
GB_END_DECLARE
};
BEGIN_METHOD(MatrixEdges_get, GB_STRING src; GB_STRING dst)
THIS->v.src = get_vertex(THIS, STRING(src), LENGTH(src));
THIS->v.dst = get_vertex(THIS, STRING(dst), LENGTH(dst));
GB.ReturnSelf(THIS);
END_METHOD
GB_DESC CMatrixEdges[] = {
GB_DECLARE_VIRTUAL(".Matrix.Edges"),
GB_INHERITS(".Graph.Edges"),
GB_METHOD("_get", ".Matrix.Edge", MatrixEdges_get, "(Src)s(Dst)s"),
GB_END_DECLARE
};
BEGIN_PROPERTY(MatrixVertex_InDegree)
unsigned int i, count = GB.Count(THIS->matrix), deg = 0;
for (i = 0; i < count; i++)
if (THIS->matrix[i].edges[THIS->v.vertex].set)
deg++;
GB.ReturnInteger(deg);
END_PROPERTY
BEGIN_PROPERTY(MatrixVertex_OutDegree)
unsigned int j, count = GB.Count(THIS->matrix), deg = 0;
for (j = 0; j < count; j++)
if (THIS->matrix[THIS->v.vertex].edges[j].set)
deg++;
GB.ReturnInteger(deg);
END_PROPERTY
BEGIN_PROPERTY(MatrixVertex_Name)
char *name = THIS->matrix[THIS->v.vertex].name;
if (READ_PROPERTY) {
GB.ReturnString(name);
return;
}
GB.HashTable.Remove(THIS->names, name, GB.StringLength(name));
GB.FreeString(&THIS->matrix[THIS->v.vertex].name);
THIS->matrix[THIS->v.vertex].name =
GB.NewString(PSTRING(), PLENGTH());
GB.HashTable.Add(THIS->names, PSTRING(), PLENGTH(),
(void *) (intptr_t) THIS->v.vertex);
END_PROPERTY
BEGIN_PROPERTY(MatrixVertex_Value)
if (READ_PROPERTY) {
GB.ReturnVariant(&THIS->matrix[THIS->v.vertex].val);
return;
}
GB.StoreVariant(PROP(GB_VARIANT), &THIS->matrix[THIS->v.vertex].val);
END_METHOD
GB_DESC CMatrixVertex[] = {
GB_DECLARE_VIRTUAL(".Matrix.Vertex"),
GB_INHERITS(".Graph.Vertex"),
GB_PROPERTY_READ("InDegree", "i", MatrixVertex_InDegree),
GB_PROPERTY_READ("OutDegree", "i", MatrixVertex_OutDegree),
GB_PROPERTY("Name", "s", MatrixVertex_Name),
GB_PROPERTY("Value", "v", MatrixVertex_Value),
GB_END_DECLARE
};
BEGIN_PROPERTY(MatrixEdge_Src)
int src = THIS->v.src;
GB.ReturnString(THIS->matrix[src].name);
END_PROPERTY
BEGIN_PROPERTY(MatrixEdge_Dst)
int dst = THIS->v.dst;
GB.ReturnString(THIS->matrix[dst].name);
END_PROPERTY
BEGIN_PROPERTY(MatrixEdge_Weight)
int src = THIS->v.src, dst = THIS->v.dst;
if (READ_PROPERTY) {
GB.ReturnFloat(THIS->matrix[src].edges[dst].weight);
return;
}
THIS->matrix[src].edges[dst].weight = VPROP(GB_FLOAT);
if (!THIS->directed && src != dst)
THIS->matrix[dst].edges[src].weight = VPROP(GB_FLOAT);
END_PROPERTY
GB_DESC CMatrixEdge[] = {
GB_DECLARE_VIRTUAL(".Matrix.Edge"),
GB_INHERITS(".Graph.Edge"),
GB_PROPERTY_READ("Src", "s", MatrixEdge_Src),
GB_PROPERTY_READ("Dst", "s", MatrixEdge_Dst),
GB_PROPERTY("Weight", "f", MatrixEdge_Weight),
GB_PROPERTY_READ("Source", "s", MatrixEdge_Src),
GB_PROPERTY_READ("Destination", "s", MatrixEdge_Dst),
GB_END_DECLARE
};
|