Skip to content

Instantly share code, notes, and snippets.

@N-Coder
Last active March 2, 2022 13:31
Show Gist options
  • Save N-Coder/1ae940169074683f610a6f9a173609a2 to your computer and use it in GitHub Desktop.
Save N-Coder/1ae940169074683f610a6f9a173609a2 to your computer and use it in GitHub Desktop.
mybinder.org ogdf-python
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "twelve-loading",
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-14T12:12:14.814903Z",
"iopub.status.busy": "2021-09-14T12:12:14.814057Z",
"iopub.status.idle": "2021-09-14T12:12:16.920874Z",
"shell.execute_reply": "2021-09-14T12:12:16.920524Z"
}
},
"outputs": [],
"source": [
"from ogdf_python import *\n",
"from cppyy import gbl as cpp"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "knowing-characterization",
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-14T12:12:16.930852Z",
"iopub.status.busy": "2021-09-14T12:12:16.930311Z",
"iopub.status.idle": "2021-09-14T12:12:16.969318Z",
"shell.execute_reply": "2021-09-14T12:12:16.969635Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello World!\n",
"Hello All!\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Hello Error!\n"
]
}
],
"source": [
"%%cpp\n",
"\n",
"std::cout << \"Hello World!\" << std::endl;\n",
"std::cerr << \"Hello Error!\" << std::endl;\n",
"std::cout << \"Hello All!\\n\";\n",
" \n",
"ogdf::Graph G;"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "martial-allergy",
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-14T12:12:16.980660Z",
"iopub.status.busy": "2021-09-14T12:12:16.980124Z",
"iopub.status.idle": "2021-09-14T12:12:17.256498Z",
"shell.execute_reply": "2021-09-14T12:12:17.256156Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"<?xml version=\"1.0\"?>\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" version=\"1.1\" baseProfile=\"full\" viewBox=\"-11.5 -11.5 123 123\">\n",
"\t<g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"40,0,35,1.25,35,-1.25,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M0,0 L40,0\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"90,0,85,1.25,85,-1.25,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M50,0 L90,0\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"10,0,15,-1.25,15,1.25,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M100,0 L10,0\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"0,40,-1.25,35,1.25,35,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M0,0 L0,35\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"30,50,22.5,51.875,22.5,48.125,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M0,50 L30,50\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"50,30,48.125,22.5,51.875,22.5,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M50,0 L50,22.5\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"90,50,82.5,51.875,82.5,48.125,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M50,50 L90,50\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"100,40,98.75,35,101.25,35,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M100,0 L100,35\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"10,50,15,48.75,15,51.25,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M100,50 L10,50\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"0,90,-1.25,85,1.25,85,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M0,50 L0,85\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"40,100,35,101.25,35,98.75,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M0,100 L40,100\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"50,90,48.125,82.5,51.875,82.5,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M50,50 L50,82.5\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"90,100,85,101.25,85,98.75,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M50,100 L90,100\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"100,90,98.75,85,101.25,85,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M100,50 L100,85\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"10,100,15,98.75,15,101.25,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M100,100 L10,100\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"-10\" y=\"-10\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"0\" y=\"0\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">0</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"40\" y=\"-10\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"50\" y=\"0\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">1</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"90\" y=\"-10\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"100\" y=\"0\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">2</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"-10\" y=\"40\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"0\" y=\"50\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">3</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"30\" y=\"30\" width=\"40\" height=\"40\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"50\" y=\"50\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">4</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"90\" y=\"40\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"100\" y=\"50\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">5</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"-10\" y=\"90\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"0\" y=\"100\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">6</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"40\" y=\"90\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"50\" y=\"100\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">7</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"90\" y=\"90\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"100\" y=\"100\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">8</text>\n",
"\t</g>\n",
"</svg>\n"
],
"text/plain": [
"<cppyy.gbl.ogdf.GraphAttributes object at 0x55934b0f0880>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"G = cpp.G\n",
"GA = ogdf.GraphAttributes(G, ogdf.GraphAttributes.all)\n",
"GA.destroyAttributes(ogdf.GraphAttributes.nodeId)\n",
"\n",
"cppinclude(\"ogdf/basic/graph_generators/deterministic.h\")\n",
"width = height = 3\n",
"ogdf.gridGraph(G, width, height, True, False)\n",
"\n",
"for n in G.nodes:\n",
" GA.label[n] = str(n.index())\n",
" GA.x[n] = (n.index() % width) * 50 \n",
" GA.y[n] = (n.index() // height) * 50\n",
"\n",
"middle = G.numberOfNodes() // 2\n",
"GA.width[G.nodes[middle]] = 40\n",
"GA.height[G.nodes[middle]] = 40\n",
" \n",
"GA"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "varying-frame",
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-14T12:12:17.270634Z",
"iopub.status.busy": "2021-09-14T12:12:17.270248Z",
"iopub.status.idle": "2021-09-14T12:12:17.272313Z",
"shell.execute_reply": "2021-09-14T12:12:17.271951Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The graph has 9 nodes\n"
]
}
],
"source": [
"%%cpp\n",
"\n",
"std::cout << \"The graph has \" << G.numberOfNodes() << \" nodes\\n\";"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "sharing-sugar",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2021-09-14T13:18:50.317866Z",
"iopub.status.busy": "2021-09-14T13:18:50.317492Z",
"iopub.status.idle": "2021-09-14T13:18:50.319354Z",
"shell.execute_reply": "2021-09-14T13:18:50.318988Z"
},
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"%%cppdef\n",
"\n",
"// implemented in C++ for efficiency\n",
"int avg_width(const ogdf::GraphAttributes &GA) {\n",
" int sum = 0;\n",
" for (auto n : GA.constGraph().nodes) {\n",
" sum += GA.width(n);\n",
" }\n",
" return sum / GA.constGraph().numberOfNodes();\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "brutal-egyptian",
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-14T12:12:17.379275Z",
"iopub.status.busy": "2021-09-14T12:12:17.311586Z",
"iopub.status.idle": "2021-09-14T12:12:17.410719Z",
"shell.execute_reply": "2021-09-14T12:12:17.410412Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The node widths are 20 20 20 20 40 20 20 20 20 20 20 20 20 20 20 20\n",
"The average width is 22\n"
]
},
{
"data": {
"text/plain": [
"{n0 °(1i+2o=3) [e0->n1, e2<-n2, e3->n3]: 20.0,\n",
" n1 °(1i+2o=3) [e0<-n0, e1->n2, e5->n4]: 20.0,\n",
" n2 °(1i+2o=3) [e1<-n1, e2->n0, e7->n5]: 20.0,\n",
" n3 °(2i+2o=4) [e3<-n0, e4->n4, e8<-n5, e9->n6]: 20.0,\n",
" n4 °(2i+2o=4) [e4<-n3, e5<-n1, e6->n5, e11->n7]: 40.0,\n",
" n5 °(2i+2o=4) [e6<-n4, e7<-n2, e8->n3, e13->n8]: 20.0,\n",
" n6 °(2i+1o=3) [e9<-n3, e10->n7, e14<-n8]: 20.0,\n",
" n7 °(2i+1o=3) [e10<-n6, e11<-n4, e12->n8]: 20.0,\n",
" n8 °(2i+1o=3) [e12<-n7, e13<-n5, e14->n6]: 20.0}"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(\"The node widths are\", GA.width())\n",
"print(\"The average width is\", cpp.avg_width(GA)) # call your own C++ functions from python\n",
"\n",
"dict(zip(G.nodes, GA.width()))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "covered-effect",
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-14T12:12:17.429846Z",
"iopub.status.busy": "2021-09-14T12:12:17.429334Z",
"iopub.status.idle": "2021-09-14T12:12:17.432465Z",
"shell.execute_reply": "2021-09-14T12:12:17.432081Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Deleting node number 4: n4 °(2i+2o=4) [e4<-n3, e5<-n1, e6->n5, e11->n7]\n",
"Node number 4 now is: n5\n",
"The last node is: n8\n",
"The node with the biggest ID is: n8\n",
"The line in the middle is edge n5--e8->n3\n"
]
},
{
"data": {
"text/html": [
"<?xml version=\"1.0\"?>\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:ev=\"http://www.w3.org/2001/xml-events\" version=\"1.1\" baseProfile=\"full\" viewBox=\"-11.5 -11.5 123 123\">\n",
"\t<g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"40,0,35,1.25,35,-1.25,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M0,0 L40,0\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"90,0,85,1.25,85,-1.25,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M50,0 L90,0\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"10,0,15,-1.25,15,1.25,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M100,0 L10,0\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"0,40,-1.25,35,1.25,35,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M0,0 L0,35\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"100,40,98.75,35,101.25,35,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M100,0 L100,35\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"10,50,15,48.75,15,51.25,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M100,50 L10,50\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"0,90,-1.25,85,1.25,85,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M0,50 L0,85\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"40,100,35,101.25,35,98.75,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M0,100 L40,100\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"90,100,85,101.25,85,98.75,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M50,100 L90,100\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"100,90,98.75,85,101.25,85,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M100,50 L100,85\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t\t<g>\n",
"\t\t\t<polygon points=\"10,100,15,98.75,15,101.25,\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t\t<path fill=\"none\" d=\" M100,100 L10,100\" stroke=\"#000000\" stroke-width=\"1.000000px\" />\n",
"\t\t</g>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"-10\" y=\"-10\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"0\" y=\"0\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">0</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"40\" y=\"-10\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"50\" y=\"0\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">1</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"90\" y=\"-10\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"100\" y=\"0\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">2</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"-10\" y=\"40\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"0\" y=\"50\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">3</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"90\" y=\"40\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"100\" y=\"50\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">5</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"-10\" y=\"90\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"0\" y=\"100\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">6</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"40\" y=\"90\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"50\" y=\"100\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">7</text>\n",
"\t</g>\n",
"\t<g>\n",
"\t\t<rect x=\"90\" y=\"90\" width=\"20\" height=\"20\" fill=\"#FFFFFF\" stroke-width=\"1.000000px\" stroke=\"#000000\" />\n",
"\t\t<text x=\"100\" y=\"100\" text-anchor=\"middle\" dominant-baseline=\"middle\" font-family=\"Arial\" font-size=\"10\" fill=\"#000000\">8</text>\n",
"\t</g>\n",
"</svg>\n"
],
"text/plain": [
"<cppyy.gbl.ogdf.GraphAttributes object at 0x55934b0f0880>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(\"Deleting node number %s:\" % middle, repr(G.nodes[middle]))\n",
"G.delNode(G.nodes[middle])\n",
"print(\"Node number %s now is:\" % middle, G.nodes[middle])\n",
"print(\"The last node is:\", G.nodes[-1])\n",
"print(\"The node with the biggest ID is:\", G.nodes.byid(G.maxNodeIndex()))\n",
"\n",
"print(\"The line in the middle is edge\", repr(G.searchEdge(\n",
" G.nodes.byid(width * (height // 2)), \n",
" G.nodes.byid(width * (height // 2) + width - 1))))\n",
"\n",
"GA"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "wrapped-mexican",
"metadata": {
"execution": {
"iopub.execute_input": "2021-09-14T12:12:17.439841Z",
"iopub.status.busy": "2021-09-14T12:12:17.439298Z",
"iopub.status.idle": "2021-09-14T12:12:17.444310Z",
"shell.execute_reply": "2021-09-14T12:12:17.443968Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Help on Graph in module __main__ object:\n",
"\n",
"class Graph(cppyy.gbl.CPPInstance)\n",
" | https://ogdf.github.io/doc/ogdf/classogdf_1_1_graph.html#\n",
" | \n",
" | Method resolution order:\n",
" | Graph\n",
" | cppyy.gbl.CPPInstance\n",
" | builtins.object\n",
" | \n",
" | Methods defined here:\n",
" | \n",
" | __assign__(...)\n",
" | ogdf::Graph& ogdf::Graph::operator=(const ogdf::Graph& G)\n",
" | \n",
" | __init__(...)\n",
" | Graph::Graph()\n",
" | Graph::Graph(const ogdf::Graph& G)\n",
" | \n",
" | adjEntryArrayTableSize(...)\n",
" | int ogdf::Graph::adjEntryArrayTableSize()\n",
" | \n",
" | allEdges = cppyy template proxy (internal)\n",
" | allNodes = cppyy template proxy (internal)\n",
" | chooseEdge(...)\n",
" | ogdf::EdgeElement* ogdf::Graph::chooseEdge(std::function<bool(ogdf::EdgeElement*)> includeEdge = [] (ogdf::edge) {\n",
" | return true;\n",
" | }\n",
" | , bool isFastTest = true)\n",
" | \n",
" | chooseNode(...)\n",
" | ogdf::NodeElement* ogdf::Graph::chooseNode(std::function<bool(ogdf::NodeElement*)> includeNode = [] (ogdf::node) {\n",
" | return true;\n",
" | }\n",
" | , bool isFastTest = true)\n",
" | \n",
" | clear(...)\n",
" | void ogdf::Graph::clear()\n",
" | \n",
" | collapse = cppyy template proxy (internal)\n",
" | consistencyCheck(...)\n",
" | void ogdf::Graph::consistencyCheck()\n",
" | \n",
" | contract(...)\n",
" | ogdf::NodeElement* ogdf::Graph::contract(ogdf::edge e)\n",
" | \n",
" | delEdge(...)\n",
" | void ogdf::Graph::delEdge(ogdf::edge e)\n",
" | \n",
" | delNode(...)\n",
" | void ogdf::Graph::delNode(ogdf::node v)\n",
" | \n",
" | edgeArrayTableSize(...)\n",
" | int ogdf::Graph::edgeArrayTableSize()\n",
" | \n",
" | empty(...)\n",
" | bool ogdf::Graph::empty()\n",
" | \n",
" | firstEdge(...)\n",
" | ogdf::EdgeElement* ogdf::Graph::firstEdge()\n",
" | \n",
" | firstNode(...)\n",
" | ogdf::NodeElement* ogdf::Graph::firstNode()\n",
" | \n",
" | genus(...)\n",
" | int ogdf::Graph::genus()\n",
" | \n",
" | insert(...)\n",
" | void ogdf::Graph::insert(const ogdf::Graph& G, ogdf::NodeArray<ogdf::NodeElement*>& nodeMap)\n",
" | void ogdf::Graph::insert(const ogdf::Graph& G)\n",
" | \n",
" | lastEdge(...)\n",
" | ogdf::EdgeElement* ogdf::Graph::lastEdge()\n",
" | \n",
" | lastNode(...)\n",
" | ogdf::NodeElement* ogdf::Graph::lastNode()\n",
" | \n",
" | maxAdjEntryIndex(...)\n",
" | int ogdf::Graph::maxAdjEntryIndex()\n",
" | \n",
" | maxEdgeIndex(...)\n",
" | int ogdf::Graph::maxEdgeIndex()\n",
" | \n",
" | maxNodeIndex(...)\n",
" | int ogdf::Graph::maxNodeIndex()\n",
" | \n",
" | move(...)\n",
" | void ogdf::Graph::move(ogdf::edge e, ogdf::adjEntry adjSrc, ogdf::Direction dirSrc, ogdf::adjEntry adjTgt, ogdf::Direction dirTgt)\n",
" | \n",
" | moveAdj(...)\n",
" | void ogdf::Graph::moveAdj(ogdf::adjEntry adjMove, ogdf::Direction dir, ogdf::adjEntry adjPos)\n",
" | \n",
" | moveAdjAfter(...)\n",
" | void ogdf::Graph::moveAdjAfter(ogdf::adjEntry adjMove, ogdf::adjEntry adjAfter)\n",
" | \n",
" | moveAdjBefore(...)\n",
" | void ogdf::Graph::moveAdjBefore(ogdf::adjEntry adjMove, ogdf::adjEntry adjBefore)\n",
" | \n",
" | moveRegisterArray = cppyy template proxy (internal)\n",
" | moveSource(...)\n",
" | void ogdf::Graph::moveSource(ogdf::edge e, ogdf::node w)\n",
" | void ogdf::Graph::moveSource(ogdf::edge e, ogdf::adjEntry adjSrc, ogdf::Direction dir)\n",
" | \n",
" | moveTarget(...)\n",
" | void ogdf::Graph::moveTarget(ogdf::edge e, ogdf::node w)\n",
" | void ogdf::Graph::moveTarget(ogdf::edge e, ogdf::adjEntry adjTgt, ogdf::Direction dir)\n",
" | \n",
" | newEdge(...)\n",
" | ogdf::EdgeElement* ogdf::Graph::newEdge(ogdf::node v, ogdf::node w)\n",
" | ogdf::EdgeElement* ogdf::Graph::newEdge(ogdf::node v, ogdf::node w, int index)\n",
" | ogdf::EdgeElement* ogdf::Graph::newEdge(ogdf::adjEntry adjSrc, ogdf::adjEntry adjTgt, ogdf::Direction dir = Direction::after)\n",
" | ogdf::EdgeElement* ogdf::Graph::newEdge(ogdf::node v, ogdf::adjEntry adjTgt)\n",
" | ogdf::EdgeElement* ogdf::Graph::newEdge(ogdf::adjEntry adjSrc, ogdf::node w)\n",
" | \n",
" | newNode(...)\n",
" | ogdf::NodeElement* ogdf::Graph::newNode()\n",
" | ogdf::NodeElement* ogdf::Graph::newNode(int index)\n",
" | \n",
" | nodeArrayTableSize(...)\n",
" | int ogdf::Graph::nodeArrayTableSize()\n",
" | \n",
" | numberOfEdges(...)\n",
" | int ogdf::Graph::numberOfEdges()\n",
" | \n",
" | numberOfNodes(...)\n",
" | int ogdf::Graph::numberOfNodes()\n",
" | \n",
" | registerArray(...)\n",
" | ogdf::ListIteratorBase<ogdf::NodeArrayBase*,false,false> ogdf::Graph::registerArray(ogdf::NodeArrayBase* pNodeArray)\n",
" | ogdf::ListIteratorBase<ogdf::EdgeArrayBase*,false,false> ogdf::Graph::registerArray(ogdf::EdgeArrayBase* pEdgeArray)\n",
" | ogdf::ListIteratorBase<ogdf::AdjEntryArrayBase*,false,false> ogdf::Graph::registerArray(ogdf::AdjEntryArrayBase* pAdjArray)\n",
" | \n",
" | registerStructure(...)\n",
" | ogdf::ListIteratorBase<ogdf::GraphObserver*,false,false> ogdf::Graph::registerStructure(ogdf::GraphObserver* pStructure)\n",
" | \n",
" | representsCombEmbedding(...)\n",
" | bool ogdf::Graph::representsCombEmbedding()\n",
" | \n",
" | resetEdgeIdCount(...)\n",
" | void ogdf::Graph::resetEdgeIdCount(int maxId)\n",
" | \n",
" | reverseAdjEdges(...)\n",
" | void ogdf::Graph::reverseAdjEdges(ogdf::node v)\n",
" | void ogdf::Graph::reverseAdjEdges()\n",
" | \n",
" | reverseAllEdges(...)\n",
" | void ogdf::Graph::reverseAllEdges()\n",
" | \n",
" | reverseEdge(...)\n",
" | void ogdf::Graph::reverseEdge(ogdf::edge e)\n",
" | \n",
" | searchEdge(...)\n",
" | ogdf::EdgeElement* ogdf::Graph::searchEdge(ogdf::node v, ogdf::node w, bool directed = false)\n",
" | \n",
" | sort = cppyy template proxy (internal)\n",
" | split(...)\n",
" | ogdf::EdgeElement* ogdf::Graph::split(ogdf::edge e)\n",
" | \n",
" | splitNode(...)\n",
" | ogdf::NodeElement* ogdf::Graph::splitNode(ogdf::adjEntry adjStartLeft, ogdf::adjEntry adjStartRight)\n",
" | \n",
" | swapAdjEdges(...)\n",
" | void ogdf::Graph::swapAdjEdges(ogdf::adjEntry adj1, ogdf::adjEntry adj2)\n",
" | \n",
" | unregisterArray(...)\n",
" | void ogdf::Graph::unregisterArray(ogdf::ListIterator<ogdf::NodeArrayBase*> it)\n",
" | void ogdf::Graph::unregisterArray(ogdf::ListIterator<ogdf::EdgeArrayBase*> it)\n",
" | void ogdf::Graph::unregisterArray(ogdf::ListIterator<ogdf::AdjEntryArrayBase*> it)\n",
" | \n",
" | unregisterStructure(...)\n",
" | void ogdf::Graph::unregisterStructure(ogdf::ListIterator<ogdf::GraphObserver*> it)\n",
" | \n",
" | unsplit(...)\n",
" | void ogdf::Graph::unsplit(ogdf::node u)\n",
" | void ogdf::Graph::unsplit(ogdf::edge eIn, ogdf::edge eOut)\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors defined here:\n",
" | \n",
" | __dict__\n",
" | dictionary for instance variables (if defined)\n",
" | \n",
" | __weakref__\n",
" | list of weak references to the object (if defined)\n",
" | \n",
" | edges\n",
" | \n",
" | nodes\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Methods inherited from cppyy.gbl.CPPInstance:\n",
" | \n",
" | __add__(self, value, /)\n",
" | Return self+value.\n",
" | \n",
" | __bool__(self, /)\n",
" | self != 0\n",
" | \n",
" | __destruct__(...)\n",
" | call the C++ destructor\n",
" | \n",
" | __dispatch__(...)\n",
" | dispatch to selected overload\n",
" | \n",
" | __eq__(self, value, /)\n",
" | Return self==value.\n",
" | \n",
" | __ge__(self, value, /)\n",
" | Return self>=value.\n",
" | \n",
" | __getitem__(...)\n",
" | pointer dereferencing\n",
" | \n",
" | __gt__(self, value, /)\n",
" | Return self>value.\n",
" | \n",
" | __hash__(self, /)\n",
" | Return hash(self).\n",
" | \n",
" | __invert__(self, /)\n",
" | ~self\n",
" | \n",
" | __le__(self, value, /)\n",
" | Return self<=value.\n",
" | \n",
" | __lt__(self, value, /)\n",
" | Return self<value.\n",
" | \n",
" | __mul__(self, value, /)\n",
" | Return self*value.\n",
" | \n",
" | __ne__(self, value, /)\n",
" | Return self!=value.\n",
" | \n",
" | __neg__(self, /)\n",
" | -self\n",
" | \n",
" | __pos__(self, /)\n",
" | +self\n",
" | \n",
" | __radd__(self, value, /)\n",
" | Return value+self.\n",
" | \n",
" | __repr__(self, /)\n",
" | Return repr(self).\n",
" | \n",
" | __rmul__(self, value, /)\n",
" | Return value*self.\n",
" | \n",
" | __rsub__(self, value, /)\n",
" | Return value-self.\n",
" | \n",
" | __rtruediv__(self, value, /)\n",
" | Return value/self.\n",
" | \n",
" | __smartptr__(...)\n",
" | get associated smart pointer, if any\n",
" | \n",
" | __str__(self, /)\n",
" | Return str(self).\n",
" | \n",
" | __sub__(self, value, /)\n",
" | Return self-value.\n",
" | \n",
" | __truediv__(self, value, /)\n",
" | Return self/value.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Static methods inherited from cppyy.gbl.CPPInstance:\n",
" | \n",
" | __new__(*args, **kwargs) from cppyy.CPPScope\n",
" | Create and return a new object. See help(type) for accurate signature.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors inherited from cppyy.gbl.CPPInstance:\n",
" | \n",
" | __python_owns__\n",
" | If true, python manages the life time of this object\n",
"\n"
]
}
],
"source": [
"# we have python docs and also the doxygen docs linked from there\n",
"help(G)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ogdf-python",
"language": "python",
"name": "ogdf-python"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
FROM ncoder/ogdf:2022.02-dogwood
RUN pip install --no-cache-dir notebook jupyterhub jupyterlab
ARG NB_USER=jovyan
ARG NB_UID=1000
ENV USER ${NB_USER}
ENV NB_UID ${NB_UID}
ENV HOME /home/${NB_USER}
RUN adduser --disabled-password \
--gecos "Default user" \
--uid ${NB_UID} \
${NB_USER}
# Make sure the contents of our repo are in ${HOME}
COPY . ${HOME}
USER root
RUN chown -R ${NB_UID} ${HOME}
USER ${NB_USER}
WORKDIR ${HOME}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment