2009-03-04 20 views
0

グリーティング誰もが、この例外をクリアでいくつかの助けが必要になるだろう。 Microsoft Visual C++ 6.0で私のコンパイルされたプログラムをデバッグするとき、私は次の取得アクセス違反

Loaded 'ntdll.dll', no matching symbolic information found. 
Loaded 'C:\WINDOWS\system32\kernel32.dll', no matching symbolic information found. 
Loaded 'C:\WINDOWS\system32\tsappcmp.dll', no matching symbolic information found. 
Loaded 'C:\WINDOWS\system32\msvcrt.dll', no matching symbolic information found. 
Loaded 'C:\WINDOWS\system32\advapi32.dll', no matching symbolic information found. 
Loaded 'C:\WINDOWS\system32\rpcrt4.dll', no matching symbolic information found. 
First-chance exception in SA.exe: 0xC0000005: Access Violation. 

ここでは、デバッガから関連のスクリーンショットです。

表示ostream.h:

http://img237.imageshack.us/my.php?image=accessviolation.png'>http://img237.imageshack.us/img237/1116/accessviolation。

http://img509.imageshack.us/my.php?image=accessviolation2.png'>http://img509:main.ccpを表示th.png」国境= '0' />

.imageshack.us/img509/3619/accessviolation2.th.png 'border =' 0 '/>

私はnullポインタのために自分のコードを捜索しようとしているし、また無視しようとしました運がないという例外はもうありません。

main.ccp

#include <iostream> 

#include "SA.h" 

using namespace std; // For the use of text generation in application 


int main() 
{ 
    SimAnneal Go; 

    cout << "Quadratic Function" << endl 
     << "Solving method: Simulated Annealing" << endl; 

    cout << "\nSelect desired Initial Temperature:" << endl 
     << "> "; 
    cin >> Go.T_initial; 

    cout << "\nSelect desired number of Temperature Iterations:" << endl 
     << "> "; 
    cin >> Go.N_max; 

    cout << "\nSelect desired number of step Iterations:" << endl 
     << "> "; 
    cin >> Go.N_step; 

    cout << "\nSelect desired Absolute Temperature:" << endl 
     << "> "; 
    cin >> Go.T_abs; 

    Go.LoadCities(); 

    Go.Initialize(); 

    Go.SA(); 

    system ("PAUSE"); 

    return 0; 
} 

SA.cpp

はどのような援助がはるかにappriciatedされるだろう
#include <math.h> 
#include <iostream> 
#include <fstream>   
#include <iterator> 
#include <iomanip> 
#include <time.h>   
#include <cstdlib>   

#include "SA.h" 

using namespace std; 


void SimAnneal::SA() 
{ 
    T = T_initial; 
    E_current = E_initial; 


     for (int N_temperatures = 1 ; N_temperatures <= N_max ; N_temperatures++) 
     { 
      Metropolis(T, N_step, N_temperatures); 
      T = Schedule(T, N_temperatures); 

     if (T <= T_abs) 
      break; 
     } 

    cout << "\nResults:" << endl 
    << "Distance> " << E_current << endl 
    << "Temperature> " << T << endl; 

    OrderList(S_order); 
} 

void SimAnneal::Metropolis(double T_current, int N_Steps, int N_temperatures) 
{ 
    for (int i=1; i <= N_step; i++)   
     Next_State(T_current, N_temperatures);  
} 

void SimAnneal::Next_State (double T_current, int i) 
{ 
    OrderTrial(); 

    double EXP = 2.718281828; 

    double E_t = ObjFunction(S_trial); 
    double E_c = ObjFunction(S_order); 

    double deltaE = E_t - E_c;        
     if (deltaE <= 0) 
     {  
     EquateArray(); 
     E_current = E_t; 
    } 
     else 
     { 
     double R = Random_Number_Generator(1,0); 
     double Ratio = 1-(float)i/(float)N_max;   
     double ctrl_pram = pow(EXP, (-deltaE/T_current)); 

      if (R < ctrl_pram*Ratio)       
      { 
      EquateArray(); 
      E_current = E_t; 
     } 
     else 
      E_current = E_c; 
    } 
} 

double SimAnneal::Schedule (double Temp, int i) 
{ 
    double CoolingRate = 0.9999; 

    return Temp *= CoolingRate; 
} 

double SimAnneal::ObjFunction (double CityOrder []) 
{ 
    int a, b; 

    double distance = 0; 

    for (int i = 0; i < 15 - 1; i++) 
    { 
     a = CityOrder [i]; 
     b = CityOrder [i + 1]; 

     distance += CityArray [a][b]; 
    } 

    return distance; 
} 

void SimAnneal::Initialize() 
{ 
    int a, b; 

    double distance = 0; 

    OrderInt(); 

    for (int i = 0; i < 15 -1; i++) 
    { 
     a = S_order [i]; 
     b = S_order [i + 1]; 

     distance += CityArray [a][b]; 
    } 

    E_initial = distance; 
} 

void SimAnneal::EquateArray() 
{ 
    for (int i = 0; i < 15; i++) 
    { 
     S_order [i] = S_trial [i]; 
    } 
} 

void SimAnneal::OrderInt() 
{ 
    for (int i = 0; i <15; i++) 
    { 
     S_order [i] = i; 
    } 
} 

void SimAnneal::OrderTrial() 
{ 
    for (int i = 0; i < 15; i++) 
    { 
     S_trial [i] = S_order [i]; 
    } 

    SwapNum1 = (int)Random_Number_Generator(15, 0);   
    SwapNum2 = (int)Random_Number_Generator(15, 0); 

    for (int n = 0; n <= 100000; n++)      
    { 
     SwapNum2 = (int)Random_Number_Generator(15, 0); 

     if (SwapNum1 != SwapNum2) 
      break; 
    } 

    S_trial [SwapNum1] = S_order [SwapNum2]; 
    S_trial [SwapNum2] = S_order [SwapNum1]; 
} 

void SimAnneal::OrderList (double array[]) 
{ 
    cout << "Array List : " << endl; 
    for (int i = 0; i < 15; i++) 
    { 
     cout << " > " << array[i] << endl; 
    } 

    cout << "End of array" << endl; 
} 

void SimAnneal::LoadCities() 
{ 
    int x, y; 

    for (y = 0; y < 15; y++)      
    {  
     for (x = 0; x < 15; x++)    
     {  
      if (x == y) 
      { CityArray[x][y] = 0.0; 
      } 
      else if (x != y) 
      { CityArray[x][y] = Random_Number_Generator(7, 1); 
      } 
     } 
    } 

    for (y = 0; y < 15; y++) 
    {  
     for (x = 0; x < 15; x++) 
     {  
      if (y > x) 
       CityArray[y][x] = CityArray[x][y]; 
     } 
    } 
} 

double Random_Number_Generator(double nHigh, double nLow) 
{ 
    double fr = ((rand() % ((int)nHigh*1000 - (int)nLow*1000 + 1)) + nLow)/1000; 

    return fr; 
} 

#ifndef SA_H 
    #define SA_H 


class SimAnneal { 

     double S_order [15];   
     double S_trial [15];   

     int SwapNum1; 
     int SwapNum2; 

     double CityArray [15][15]; 

     double E_initial; 
     double E_current; 

     double T; 

     void Metropolis (double, int, int); 
     void Next_State (double, int); 
     double Schedule (double, int); 
     double ObjFunction (double CityOrder []); 

     void EquateArray(); 
     void OrderInt(); 
     void OrderTrial(); 
     void OrderList (double array[]); 

     void WriteResults (double, double, double, double, double); 

     public: 
     int N_step; 
     int N_max; 
     double T_initial; 
     double T_abs; 

     void SA(); 
     void Initialize(); 
     void LoadCities(); 
    }; 


    double Random_Number_Generator(double nHigh, double nLow); 


#endif 

SA.h

:ここに私のスクリプトの3つの主要なコンポーネントがあります。私はすべて自分自身のアイデアがありません。

+0

を識別するために/ EHA

でコンパイルする。これは、コンパイルし、 VS2008で正常に動作します。それがVC6コンパイラのバグでない限り、コードに問題があるとは思わないでください。 – drby

+0

クラッシュが発生したときに使用している入力値を入力してください。 –

+0

1つのコンパイラで1つのモジュールをコンパイルしておらず、もう1つのコンパイラで別のモジュールをコンパイルしていませんか?きれいにして、エラーが消えるかどうか確認してください。また、入力範囲をチェックしていないようです(T_Initial> 0、T_abs <0の場合はT_current = 0の場合があります)。 – johnny

答えて

1

あなたが投稿したコードはコンパイルさえないでしょう:

1)

cin >> Go.Write; 

SimAnnealクラスには、このような変数はありません。

2)

Go.SA(Go.Write) 

あなたSA方法は、任意のパラメータを受け付けません。

もう一つは

、なぜあなたはVC++ 6.0で直接デバッグモードでプロジェクトを実行しませんか?スクリーンショット上のVSは明らかに200 * X *です。

は、スクリーンショットによると、あなたがライン上でクラッシュしている:あなたの出力ストリームは、何らかの方法でバラバラされていない限り、あまり意味がありません

cout << "Quadratic Function" << endl 
    << "Solving method: Simulated Annealing" << endl; 

。クラッシュが発生する前にコンソールを見てみましたか?

+0

アプリケーション。これはmain.cppファイルの古いバージョンです。それを更新する必要があります。私はあまりにもそれらの行にクラッシュすることが奇妙だと思った。私はそれらを削除しようとしました、そして、それはちょうど次のセットの出力にクラッシュします。これらをすべて削除すると、(NTDLL.DLL)アクセス違反が発生します – Raugnar

0

あなたは私が見ることができるあなたのコードでは、あまりにも致命的な何かをやっているようですが、本当にあなたがコードの行を削除しようとしている、見ていないのですか?

2

= S_order [I]。
b = S_order [i + 1];
距離+ = CityArray [A] [B]。 < ---これは疑わしいようです。私は14を=場合は、B = 15 ...はっきり範囲外... 私の2セントは

+0

しかし、私は15歳未満で14歳未満です。したがって、私は13歳を超えることはできません。 –

+0

私はこのエラーが最後に問題だった、私はクラスでプログラム全体を書き直す前に。しかし、if条件としてif(if i = 0; i <15 - 1; i ++)という式は13にしかなりません。したがって最大i = 13と最大b = S_order [14]は今日まで完全に合法であった。S – Raugnar

+0

問題は14ではなく、S_order [14]から出てくる値である。 –

0
for (int i = 0; i < 15; i++) 
{ 
    S_trial [i] = S_order [i]; 
} 

// .... 
for (int i = 0; i <15; i++) 
{ 
    S_order [i] = i; 
} 

両方のループが高すぎます。あなたは常に、コードの周りのtry {}キャッチ(...){}ブロックを置くことができる14の代わりに、15

+0

実際にはありません。 double S_order [15]; double S_trial [15]; – arul

0

にそれらを変更し、問題領域