I'm writing a genetic algorithm using C++ in Eclipse 2019-09 to find an optimum aircraft landing schedule. I've been writing the program in pieces, starting at the beginning and adding them to the code, then testing them. After declaring some variables and constants,my program opens a file containing my data, reads it into an array of object type Airplane, then opens a second file for separation data, then makes some initial solutions. All of that was working.
Then I added code to fill up mu initial generation. Now my program stops after opening the first data file (successfully). It won't even read in the data. I haven't changed that part of the code; all of my changes are later in the program. I'm including my main program to the end of the block where it stops. It stops running after it prints "Reading from the file".
I'll also include the only class that is called before that point.
I'm sorry that all of my code won't go into the code block properly.
Does anyone have any ideas on what might be causing this?
#include <iostream>
#include <fstream>
#include <string>
#include <bits/stdc++.h>
#include "Airplane.h"
#include "LandingTime.h"
#include "LL.h"
//#include "Parameters.h"
using namespace std;
// Global Parameters and Constants -- change values here to fit your problem
const int P = 20; // number of planes
const int generationSize = 12;
const int maximumNumberOfGenerations = 5;
const int g = 2; // rate of cost per unit time for early landings
const int h = 3; // rate of cost per unit time for late landings
int seed = 2019;
const string filename = "CodeTestingData20planes.txt";
// Function Declarations
// void myFunction(int param[10])
int FindTotalCost(LandingTime schedule[P]);
int FindCost (int x, int t);
bool IsNotFeasible(LandingTime Solution[P], int sep[4][4]);
// The IsNotFeasible function also fixes some feasibility issues related to separation times
void Sort(LandingTime Solution[P]);
int main()
{
//Collect Data
// Collect array of airplanes
Airplane airplane[P];
int ac;
int ty;
int a;
int e;
int t;
int l;
ifstream datafile;
datafile.open(filename);
if(!datafile.is_open()){
cout << "file didn't open";
} else
{
cout << "Reading from the file" << endl;
for(int p = 0; p < P; p++)
{
cout << p;
datafile >> ac;
datafile >> a;
datafile >> ty;
datafile >> e;
datafile >> t;
datafile >> l;
airplane[p] = Airplane(ac, a, ty, e, t, l);
// write the data at the screen.
cout << airplane[p].getAircraft() << "\t" << airplane[p].getType() << "\t";
cout << airplane[p].getA() << "\t" <<airplane[p].getE() << "\t";
cout << airplane[p].getT() << "\t" << airplane[p].getL();
cout << "\n";
}//end of for p loop
datafile.close();
cout << "data file closed";
} // end of else
This is the class cpp file:
#include "Airplane.h"
namespace std {
Airplane::Airplane() {
// TODO Auto-generated constructor stub
}
Airplane::Airplane(int ac, int a, int ty, int e, int t, int l){
aircraft = ac;
A = a;
type = ty;
E = e;
T = t;
L = l;
}
Airplane::~Airplane() {
// TODO Auto-generated destructor stub
}
void Airplane::setAircraft(int ac){
aircraft = ac;
}
void Airplane::setType(int ty){
type = ty;
}
void Airplane::setA(int a){
A = a;
}
void Airplane::setE(int e){
E = e;
}
void Airplane::setT(int t){
T = t;
}
void Airplane::setL(int l){
L = l;
}
int Airplane::getAircraft(){
return aircraft;
}
int Airplane::getType(){
return type;
}
int Airplane::getA(){
return A;
}
int Airplane::getE(){
return E;
}
int Airplane::getT(){
return T;
}
int Airplane::getL(){
return L;
}
} /* namespace std */
This is the class .h file
#ifndef AIRPLANE_H_
#define AIRPLANE_H_
namespace std {
class Airplane {
public:
// Class member variables
int aircraft; // Airplane identifier
int A; // Arrival time in ATC airspace
int type; // Type of airplane
int E; // Earliest possible landing time
int T; // Target landing time based on cruise speed
int L; // Latest possible landing time
Airplane();
Airplane(int ac, int a, int ty, int e, int t, int l);
virtual ~Airplane();
void setAircraft(int ac);
void setA(int a);
void setType(int ty);
void setE(int e);
void setT(int t);
void setL(int l);
int getAircraft();
int getA();
int getType();
int getE();
int getT();
int getL();
};
} /* namespace std */
#endif /* AIRPLANE_H_ */
Mind you, this was all working and nothing was changed and now it's not working.