C++ Calculating Shortest Path in a Directed Graph

时间:2018-05-06 17:04:21

标签: c++ const nodes shortest-path directed-graph

I am tasked with writing a program to maintain the representation of a simple network(weighted directed graph) and compute the best path between two given nodes upon request.

Currently, I am attempting to write a function to compute the simplest between two nodes, however, when attempting to run my program, I get two specific error

window.vuePersianDatetimePicker

and

<div id="app">       
    <date-picker></date-picker>
</div>


<script src="vue.js"></script>
<script src='https://wzrd.in/standalone/vue-persian-datetime-picker@latest'></script>
<script>
    Vue.component('date-picker',vuePersianDatetimePicker)
    new Vue({
        el: "#app",
        });
</script>

I am unable to debug since these two primary errors are not allowing my program to run. Is there any particular reason for these errors?

Thanks in advance!

This is the node structure defined in Graph.h

Severity    Code    Description Project File    Line    Suppression State
Error   C3863   array type 'bool [openNode]' is not assignable  P   127 

And here is the particular code that causes the errors.

Severity    Code    Description Project File    Line    Suppression State
Error   C3863   array type 'int [openNode]' is not assignable   

Any change suggestions would be much appreciated!

1 个答案:

答案 0 :(得分:2)

You have invalid code at the beginning of your error: C:\projects\opencv- python\opencv\modules\calib3d\src\calibration.cpp:3334: error: (-215) nimages > 0 in function cv::calibrateCamera function:

import numpy as np
import cv2

numero = 25
nx = 9
ny = 6
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((nx*ny,3), np.float32)
objp[:,:2] = np.mgrid[0:ny,0:nx].T.reshape(-1,2)

# Arrays to store object points and image points from all the images.
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.

#image adress
img = cv2.imread('captureL'+ str(numero)+'.png')

#color to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

#find and draw ChessboardsCorners
ret, corners = cv2.findChessboardCorners(gray,(nx,ny),None  )

if ret == True:
    cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)   
    draw_chess = cv2.drawChessboardCorners(img, (nx,ny), corners, ret)
    cv2.imshow('video testR',draw_chess)

    #camera calibration
    ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)



cv2.waitKey()
cv2.destroyAllWindows()

You cannot use variables to create arrays on the stack (which is what you are trying to do there), because the compiler doesn't know the value of shortestPath at compile time (which is needed to determine the stack size).

Why don't you use a vector, like:

bool known[openNode];
int distance[openNode];
GraphNode*  previous[openNode];

Using this method makes the for loop below obsolete aswell.