{"id":5429,"date":"2024-06-19T15:31:06","date_gmt":"2024-06-19T13:31:06","guid":{"rendered":"https:\/\/oopm.org\/?page_id=5429"},"modified":"2024-11-19T12:11:31","modified_gmt":"2024-11-19T11:11:31","slug":"11-3-graph-example","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=5429","title":{"rendered":"11.3 Graph example"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages5429&print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/pdf.png\" alt=\"image_pdf\" title=\"View PDF\" \/><\/a><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages5429&print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">In this section, we show a further example of using virtual class attributes from the domain of graphs. Graphs have many applications. Here we sketch the structure of a graph of cities connected with roads. Such a graph may e.g. be used for tour planning. We also show a very brief sketch of a graph for computer networks connected with cables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We start by defining a class defining an overall structure of a graph:<\/p>\n\n\n\n<pre class=\"wp-block-code has-custom-color-1-background-color has-background\"><code>   <strong>class<\/strong> Graph:\n      <strong>class<\/strong> Node(id: <strong>var<\/strong> String):&lt; \n         addEdge(to: <strong>ref<\/strong> Node)-&gt; E: <strong>ref<\/strong> Edge:&lt; \n            :::\n         :::\n      <strong>class<\/strong> Edge(from: <strong>ref<\/strong> Node, to: <strong>ref<\/strong> Node):&lt;    \n         :::\n      nodes: <strong>obj<\/strong> Set(#Node)\n      addNode(nm: <strong>var<\/strong> String) -&gt; n: <strong>ref<\/strong> Node:\n         :::\n      display: ...\n      :::<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Class <code>Graph<\/code> has the following attributes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Two virtual classes <code>Node<\/code> and <code>Edge<\/code> representing the nodes and edges of the graph. They will be further extended in subclasses of <code>Graph<\/code> as we shall se below.<\/li>\n\n\n\n<li>An object <code>nodes<\/code>, which contains the set of nodes of a given graph. <\/li>\n\n\n\n<li>A method <code>addNode<\/code> for adding a <code>Node<\/code> to a given <code>Graph<\/code>.<\/li>\n\n\n\n<li>A method <code>display<\/code> for displaying the graph.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Class <code>Node<\/code> has a method <code>addEdge<\/code> for adding an edge from the <code>Node<\/code> to a node represented by the parameter <code>to<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>Node<\/code> class has the structure:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> <strong>class<\/strong> Node(id: <strong>var<\/strong> String):&lt;\n    addEdge(to: <strong>ref<\/strong> Node)-&gt; e: <strong>ref<\/strong> Edge:&lt;\n       e := Edge(this(Node),to)\n       inner(addEdge)\n       edges.insert(e)\n    edges: <strong>obj<\/strong> Set(#Edge)\n    display:&lt; ...\n       displayEdges:&lt; ...<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The parameter <code>id<\/code> represents the id\/name of the <code>Node<\/code>.<\/li>\n\n\n\n<li>The method <code>addEdge<\/code> adds an <code>Edge<\/code> to the <code>Node<\/code>.<\/li>\n\n\n\n<li>The object <code>edges<\/code> holds all the edges from the <code>Node<\/code>.<\/li>\n\n\n\n<li>The method displays the <code>Node<\/code> and <code>displayEdges<\/code> display the edges of the <code>Node<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">In this simple example, the <code>Edge<\/code> class just has a <code>display<\/code> method, which invokes <code>inner<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code has-custom-color-1-background-color has-background\"><code>   <strong>class<\/strong> Edge(from: <strong>ref<\/strong> Node, to: <strong>ref<\/strong> Node):&lt; \n         display:&lt;\n            inner(display)<\/code><\/pre>\n<div style=\"display:flex; gap:10px;justify-content:center\" class=\"wps-pgfw-pdf-generate-icon__wrapper-frontend\">\n\t\t<a  href=\"https:\/\/oopm.org?action=genpdf&amp;id=5429\" class=\"pgfw-single-pdf-download-button\" ><img src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-generator-for-wp\/admin\/src\/images\/PDF_Tray.svg\" title=\"Generate PDF\" style=\"width:auto; height:45px;\"><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>In this section, we show a further example of using virtual class attributes from the domain of graphs. Graphs have many applications. Here we sketch the structure of a graph of cities connected with roads. Such a graph may e.g. be used for tour planning. We also show a very brief sketch of a graph [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1410,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5429","page","type-page","status-publish","hentry"],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5429"}],"version-history":[{"count":32,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5429\/revisions"}],"predecessor-version":[{"id":9691,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5429\/revisions\/9691"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/1410"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}