小编i_u*_*net的帖子

解读Dijkstra的算法

图形

我理解如何找到Dijkstra算法所解释的从开始到结束的最短路径,我不明白的是解释.在这里,从图片中的图表,从A到E添加到我的已知集合的顺序是A,C,B,D,F,H,G,E我没有得到的,如何获得从A到E的路径,如图所示(数学方面)

java algorithm dijkstra

12
推荐指数
1
解决办法
873
查看次数

c ++顺时针排序2D点

我编写了一个程序,从 12 点钟开始以顺时针方式在图形上排列点,以便包含这些点的向量按该顺序排序。我使用 atan2 从 12 点钟获取角度,然后根据象限进行调整。我试图找出错误的来源,因为它没有正确订购它们。所以给定 4 个像照片中那样的随机点,它应该在包含向量中排序为 P1,P2,P3,P4命令 这是我的代码:

//sort_points.cpp
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;

class Point
{
    public:
        double x;
        double y;
        Point(double xx, double yy) : x(xx), y(yy) {}
        ~Point();   
        inline friend ostream& operator<<(ostream& output, const Point& point)
        {
            output << "[" << point.x << ", " << point.y <<"]";
            return output;
        }
};


Point::~Point() {;}


/* get quadrant from 12 o'clock*/
int get_quadrant (const Point& p)
{
    int result …
Run Code Online (Sandbox Code Playgroud)

c++ sorting algorithm trigonometry

3
推荐指数
1
解决办法
6274
查看次数

有没有办法在 Amazon Neptune Graph 的 Edges 上存储更多信息?

我正在做一个小的 POC 项目,我想使用亚马逊的海王星图来表示一个村庄的道路网络。

我有我打算在这个图中用作顶点的交叉点,以及街道作为边缘。一个简单的表示是:

Intersection {
   id: 1089238983,
   name: 'Madrid & 99th'
   labels: ['has_pedestrian_signals', 'four_way_intersection']
}

Street {
   id: 9808787868,
   name: 'Madrid St'
   from_int_id: 1089238983,
   to_int_id: 1089238973, 
   labels: ['has_hospital_on_street', 'is_snow_route', 'is_one_way_street']
}
Run Code Online (Sandbox Code Playgroud)

问题是AWS 的文档指出 Edges 只能有 1 个标签。

我希望能够最终根据边的属性执行遍历。我曾尝试寻找将更多数据合并到 Tinkerpop 图表中的方法,但没有发现任何有用的信息。

如果有任何建议,我将不胜感激。

amazon-web-services gremlin tinkerpop amazon-neptune

3
推荐指数
1
解决办法
328
查看次数

C++在std :: unordered_map中设置std :: tuple值

我有一个带有字符串键的无序映射和一个包含三个字符串和一个int的元组.如何访问单个元组来设置它们.

鉴于:

std::unordered_map<string,std::tuple<string, string, string,int>> foo_data_by_username;
Run Code Online (Sandbox Code Playgroud)

如何设置say的单个元组值 foo_data_by_username[some_user];

c++ unordered-map data-structures stdtuple

1
推荐指数
1
解决办法
633
查看次数

如何使用嵌套循环打印出X.

我已经搜索过这个问题的简单解决方案.

我有一个叫做的方法

printCross(int size,char display)
Run Code Online (Sandbox Code Playgroud)

它接受一个大小并打印一个X,其中包含它接收的高度和宽度的char变量.

调用方法printShape(int maxSize, char display)接受形状的最大大小并进入循环,向printCross方法发送2的倍数,直到达到最大值.

这是我的代码,但它没有给我预期的结果.

public static void drawShape(char display, int maxSize)
  {
    int currentSize = 2; //start at 2 and increase in multiples of 2 till maxSize

    while(currentSize<=maxSize)
    {
      printCross(currentSize,display);
      currentSize = currentSize + 2;//increment by multiples of 2
    }
  }

public static void printCross(int size, char display)
{
for (int row = 0; row<size; row++)  
        {  
            for (int col=0; col<size; col++)  
            {  
                if (row == col)  
                  System.out.print(display);  
                if (row == …
Run Code Online (Sandbox Code Playgroud)

java methods char shapes nested-loops

0
推荐指数
1
解决办法
2万
查看次数