警告を解決する方法を知っている人は誰でも知っていますか?new_costを返すと、returnはキャストのない整数からポインタを作る[デフォルトで有効にする]
int *cost(int num_nodes, edge new_solution[][10])
{
int new_cost = 0;
int num_edges = 1; //set number of edges back to default
int x, y, weight;
for (x = 1; x <= num_nodes; x++) //print out new_solution
{
weight =0;//find the largest tx on each node
for (y = 1; y <= num_nodes; y++)
if (new_solution[x][y].label == 1)
{
printf("\n Edge %d:(%d %d) energy:%d",
num_edges++, x, y, new_solution[x][y].weight);
if (weight < new_solution[x][y].weight) //find highest energy used per node
{
weight = new_solution[x][y].weight;
//printf("\n weight:%d accum:%d", weight, new_cost);
}
}
new_cost += weight; //find total weight
}
printf("\n Total cost is %d\n\n", new_cost);
return new_cost;
}
重み変数を配列に割り当てることができないためですか?私はコストを返すために以下の関数について同じ警告を受け取ります。誰もこれを解決する方法を知っていますか?
int *acceptance_prob(float T, int old_cost, int new_cost, edge new_solution[][10],
edge current_SA[][10], FILE *fp, int num_nodes)
{
int delta = 0, x, y;
float ap = 0.0;
int cost;
delta = (old_cost - new_cost);
ap = (exp(delta/T)); //this is the typical equation used
if (new_cost < old_cost)//if new_solution has less energy select it
{
fprintf(fp, "NO");
for (x = 1; x <= num_nodes; x++)
for (y = 1; y <= num_nodes; y++)
current_SA[x][y] = new_solution[x][y];
old_cost = new_cost;
}
else //if new_solution uses more energy maybe select it
{
if (ap > rand_float())
{
fprintf(fp,"YES");
for (x = 1; x <= num_nodes; x++)
for (y = 1; y <= num_nodes; y++)
current_SA[x][y] = new_solution[x][y];
old_cost = new_cost;
}
}
cost = old_cost;
return cost;
}
この質問は、Cについてであり、C++ではないようです。その場合は、C++タグを削除してください。 –
C++で正確に同じエラーが発生し、その答えが同等に適用されます。 2つの言語、確かに、しかし、あまりにも熱心にならないようにしましょう。 – MSalters