如何在运营商&#34; =&#34;上解决<could not =“”resolve =“”type =“”>消息对于deque <int>?

时间:2017-04-07 19:11:18

标签: c++ deque

我已经通过引用将deque变量传递给函数,并且我试图将它设置为相同类型的本地deque变量。

主要我定义:

vector<vector<deque<int>>> memo_r (max_city, vector<deque<int>>((1<<(max_city))-1));

然后在我的功能中:

double Held_Karp( ... , vector<vector<deque<int>>> &memo_r, ... ){
  deque<int> temp_route;
  temp_route.push_front(0);
  memo_r[x][y] = temp_route;
}

但temp_route中的值未放在memo_r [x] [y]中。调试时,我收到消息<could not resolve type>。为什么会这样?我可以采取哪些措施来修复/调试此问题?

谢谢!

所有相关代码:

double Held_Karp(int pos, long long unsigned city_bit, int max_city, const vector<vector<double>>&graph, vector<vector<double>> &memo, vector<vector<deque<int>>> &memo_r, deque<int> &deque_reference) {
    if (city_bit == (1<<(max_city))-1) {
        //printf("%d 1^\n",pos);
        return graph[pos+1][0+1];
    }

    if (memo[pos][city_bit] != -1) {
        //printf("%d 2^\n",pos);
        return memo[pos][city_bit];
    }

    //Ensure some "lowest_result" is accepted
    double lowest_result = numeric_limits<double>::max();
    deque<int> temp_route;
    for (int i = 0; i < max_city; i++) {
        if (i != pos && (city_bit & (1 << i)) == 0){
            deque<int> lower_deque_local;
            //printf("%d !\n",pos);
            double new_lower = graph[pos+1][i+1] + Held_Karp(i, city_bit | (1 << i), max_city, graph, memo, memo_r, lower_deque_local);
            if (lowest_result > new_lower) {
                lowest_result = new_lower;
                temp_route = lower_deque_local;
                temp_route.push_front(i);
                //Consider replace deque_reference with better lower_deque
                //Add the node you just came from
                deque_reference = lower_deque_local;
                deque_reference.push_front(i);
            }
            //lowest_result = min(lowest_result, graph[pos+1][i+1] + Held_Karp(i, city_bit | (1 << i), max_city, graph, memo));
        }
    }
    memo[pos][city_bit] = lowest_result;
    memo_r[pos][city_bit] = temp_route;
    //printf("%d 3^\n",pos);
    return lowest_result;
}

int main(int argc, char * argv[]) {
    vector<vector<double>> Graph (1000, vector<double>(1000 , 0));

    //Set to max_city - 0 not used
    int max_city = fillGraph(Graph,argv[1]);
    vector<vector<double>> memo (max_city, vector<double>((1<<(max_city))-1, -1));
    vector<vector<deque<int>>> memo_r (max_city, vector<deque<int>>((1<<(max_city))-1));
    deque<int> route;

    clock_t tStart = clock();

    double time = Held_Karp(0, 1, max_city, Graph, memo, memo_r, route);

    //Print out
    printf("OPTIMAL TOUR LENGTH: %f\n", time);

    printf("TSP TOUR:\n");
    //printf("1\n");
    int size = (int)route.size();
    for (int i = 0; i < size; i++) {
        printf("%d\n",(route.back()+1));
        route.pop_back();
    }
    //printf("1\n");

    printf("Total Time Elapsed: %fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);

}

当我在Xcode中执行时,我可以看到数据没有从temp_route复制到memo_r [x] [y]中。应显示数据的索引,但在IDE中显示为空。当我点击“更多信息”时我看到了<could not resolve type>消息。

0 个答案:

没有答案