Commit 32f3f17d authored by Sumitra Corraya's avatar Sumitra Corraya

Update globals.cc

parent 48391018
......@@ -64,18 +64,99 @@ void save_plan(const vector<const Operator *> &plan, int iter) {
out << g_plan_filename << "." << iter;
outfile.open(out.str().c_str(), ios::out);
}
for (int i = 0; i < plan.size(); i++) {
cout << plan[i]->get_name() << " (" << plan[i]->get_cost() << ")" << endl;
outfile << "(" << plan[i]->get_name() << ")" << endl;
string line;
ifstream myfile ("/sumi/savePlan.txt");
if (myfile.is_open())
{
//cout << "reading file"<< endl;;
std::vector<std::vector<std::string>> strVec;
int notFound = 0;
int row = 20, width = 50, i = 0, j = 0;
strVec.resize( row );
for( auto &i : strVec ) {
i.resize( width );
}
while ( getline (myfile,line) ) {
strVec[i][j] = line ;
if (line != "END") {
//cout << "strVec..." << strVec[i][j] << endl;
j++;
} else {
i++;
j = 0;
}
}
for (int x = 0; x < i; x++) {
//cout << "value of row" << i<< endl;;
int k = 0;
line.clear();
line = plan[k]->get_name() + " (" + std::to_string(plan[k]->get_cost()) + ")";
//cout << "first for loop" << "line"<<line << "strVec" << strVec[x][1];
if (strVec[x][0] == line) {
//cout << "first line match "<< endl;;
for (int y = 1; y <= sizeof( strVec); y++) {
k++;
if (k < plan.size()) {
line.clear();
line = plan[k]->get_name() + " (" + std::to_string(plan[k]->get_cost()) + ")";
//cout << line;
}
if (strVec[x][y] == line && k < plan.size()) {
notFound = 1; //match 1=false
//cout << y <<"line match"<< endl;
continue;
} else if ( strVec[x][y] == "END") {
break;
} else {
notFound = 0; //not match 0=true
break;
} //if end
} //for end
} //if end
if (notFound == 1 ) {
break;
}//if end
}
if (notFound == 0) {
//cout << "adding data"<< endl;;
ofstream writeFile;
writeFile.open("/sumi/savePlan.txt", std::ios_base::app) ;
for (int i = 0; i < plan.size(); i++) {
writeFile << plan[i]->get_name() << " (" << std::to_string(plan[i]->get_cost()) << ")" << endl;
cout << plan[i]->get_name() << " (" << plan[i]->get_cost() << ")" << endl;
outfile << "(" << plan[i]->get_name() << ")" << endl;
}
writeFile << "END" << endl;
writeFile.close();
outfile.close();
int plan_cost = calculate_plan_cost(plan);
cout << "Plan length: " << plan.size() << " step(s)." << endl;
cout << "Plan cost: " << plan_cost << endl;
}
} else {
ofstream collection ("/sumi/savePlan.txt");
if (collection.is_open()) {
for (int i = 0; i < plan.size(); i++) {
collection << plan[i]->get_name() << " (" << std::to_string(plan[i]->get_cost()) << ")" << endl;
cout << plan[i]->get_name() << " (" << plan[i]->get_cost() << ")" << endl;
outfile << "(" << plan[i]->get_name() << ")" << endl;
}
collection << "END" << endl;
collection.close();
outfile.close();
int plan_cost = calculate_plan_cost(plan);
cout << "Plan length: " << plan.size() << " step(s)." << endl;
cout << "Plan cost: " << plan_cost << endl;
}
}
outfile.close();
int plan_cost = calculate_plan_cost(plan);
ofstream statusfile;
statusfile.open("plan_numbers_and_cost", ios::out | ios::app);
statusfile << iter << " " << plan_cost << endl;
statusfile.close();
cout << "Plan length: " << plan.size() << " step(s)." << endl;
cout << "Plan cost: " << plan_cost << endl;
int plan_cost = calculate_plan_cost(plan);
ofstream statusfile;
statusfile.open("plan_numbers_and_cost", ios::out | ios::app);
statusfile << iter << " " << plan_cost << endl;
statusfile.close();
}
bool peek_magic(istream &in, string magic) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment