{"record":{"id":"0b09ccee84a81af7","repo":"Yalantis/uCrop","slug":"dijkstra-instance-is-not-a-graph-adjacency-matr","errorCode":null,"errorMessage":"dijkstra(): Instance is not a graph adjacency matrix.","messagePattern":"dijkstra\\(\\): Instance is not a graph adjacency matrix\\.","errorType":"exception","errorClass":"CImgInstanceException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":33932,"sourceCode":"       \\param starting_node Index of the starting node.\n       \\param ending_node Index of the ending node.\n       \\param previous_node Array that gives the previous node index in the path to the starting node\n         (optional parameter).\n       \\return Array of distances of each node to the starting node.\n       \\note image instance corresponds to the adjacency matrix of the graph.\n    **/\n    template<typename t>\n    CImg<T>& dijkstra(const unsigned int starting_node, const unsigned int ending_node,\n                      CImg<t>& previous_node) {\n      return get_dijkstra(starting_node,ending_node,previous_node).move_to(*this);\n    }\n\n    //! Return minimal path in a graph, using the Dijkstra algorithm \\newinstance.\n    template<typename t>\n    CImg<T> get_dijkstra(const unsigned int starting_node, const unsigned int ending_node,\n                         CImg<t>& previous_node) const {\n      if (_width!=_height || _depth!=1 || _spectrum!=1)\n        throw CImgInstanceException(_cimg_instance\n                                    \"dijkstra(): Instance is not a graph adjacency matrix.\",\n                                    cimg_instance);\n\n      return dijkstra(*this,_width,starting_node,ending_node,previous_node);\n    }\n\n    //! Return minimal path in a graph, using the Dijkstra algorithm.\n    CImg<T>& dijkstra(const unsigned int starting_node, const unsigned int ending_node=~0U) {\n      return get_dijkstra(starting_node,ending_node).move_to(*this);\n    }\n\n    //! Return minimal path in a graph, using the Dijkstra algorithm \\newinstance.\n    CImg<Tfloat> get_dijkstra(const unsigned int starting_node, const unsigned int ending_node=~0U) const {\n      CImg<uintT> foo;\n      return get_dijkstra(starting_node,ending_node,foo);\n    }\n\n    //! Return an image containing the character codes of specified string.","sourceCodeStart":33914,"sourceCodeEnd":33950,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L33914-L33950","documentation":"get_dijkstra() interprets the instance as a square graph adjacency matrix, requiring _width==_height and _depth==_spectrum==1. Any other shape cannot be an adjacency matrix, so CImgInstanceException is thrown.","triggerScenarios":"Calling get_dijkstra(start, end, previous_node) on a non-square image, a 3D volume, or a multi-channel image instead of an NxN single-channel weighted adjacency matrix.","commonSituations":"Passing an edge list image instead of an adjacency matrix; passing a rectangular weight map; forgetting to flatten a multi-channel graph representation.","solutions":["Build/convert the graph into an NxN single-channel adjacency matrix (width==height, depth=1, spectrum=1)","Extract the relevant channel/slice if your graph is stored multi-channel","Use the static dijkstra(distance_fn, nb_nodes, ...) overload with a custom distance functor when the graph isn't matrix-representable"],"exampleFix":"// before\nweights.get_dijkstra(s, e, prev); // weights is 100x50\n// after\nCImg<float> adj(100, 100, 1, 1, 0); // build NxN adjacency\n// ... fill adj ...\nadj.get_dijkstra(s, e, prev);","handlingStrategy":"validation","validationCode":"if (g.width() == g.height() && g.depth() == 1 && g.spectrum() == 1) { g.get_dijkstra(s, e, prev); } else { /* build NxN adjacency first */ }","typeGuard":"bool isAdjacencyMatrix(const CImg<T>& m) { return m.width() == m.height() && m.depth() == 1 && m.spectrum() == 1; }","tryCatchPattern":"try { g.get_dijkstra(s, e, prev); } catch (CImgInstanceException& e) { /* convert edge list to adjacency matrix and retry */ }","preventionTips":["Represent graphs as NxN single-channel adjacency matrices for CImg","Convert edge lists explicitly before graph algorithms","Validate start/end node bounds too (see dijkstra index error)"],"tags":["cimg","dijkstra","graph","matrix-shape"],"backgroundTag":"tensor-shape-mismatch","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}