sgraph.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #pragma once
  11. #include <ortho/structures.h>
  12. #include <stdbool.h>
  13. typedef struct snode snode;
  14. typedef struct sedge sedge;
  15. /** @brief a node of search graph @ref sgraph,
  16. * is created as a border segment between two adjusted cells of type @ref cell.
  17. *
  18. * Nodes and a search graph are created by functions @ref mkMazeGraph, @ref findSVert and @ref createSNode.
  19. */
  20. struct snode {
  21. int n_val, n_idx;
  22. snode* n_dad;
  23. sedge* n_edge;
  24. short n_adj;
  25. short save_n_adj;
  26. struct cell* cells[2]; ///< [0] - left or botom, [1] - top or right adjusted cell
  27. /** @brief edges incident on this node
  28. * -- stored as indices of the edges array in the graph
  29. */
  30. int* adj_edge_list;
  31. int index;
  32. bool isVert; /* true if node corresponds to vertical segment */
  33. };
  34. struct sedge {
  35. double weight; /* weight of edge */
  36. int cnt; /* paths using edge */
  37. /* end-points of the edge
  38. * -- stored as indices of the nodes vector in the graph
  39. */
  40. int v1, v2;
  41. };
  42. typedef struct {
  43. int nnodes, nedges;
  44. int save_nnodes, save_nedges;
  45. snode* nodes;
  46. sedge* edges;
  47. } sgraph;
  48. extern void reset(sgraph*);
  49. extern void gsave(sgraph*);
  50. extern sgraph* createSGraph(int);
  51. extern void freeSGraph (sgraph*);
  52. extern void initSEdges (sgraph* g, int maxdeg);
  53. extern int shortPath (sgraph* g, snode* from, snode* to);
  54. extern snode* createSNode (sgraph*);
  55. extern sedge* createSEdge (sgraph* g, snode* v0, snode* v1, double wt);