예제 #1
0
int main(int argc, char* argv[])
{
    if(argc != 4) {
       help_message();
       return 0;
    }
    CommonNs::TmUsage tmusg;
    CommonNs::TmStat stat;

    //////////// read the input file /////////////
    
    char buffer[200];
    fstream fin(argv[2]);
    fstream fout;
    fout.open(argv[3],ios::out);
    fin.getline(buffer,200);
    fin.getline(buffer,200);
    int junk,num;
    vector<int> data;
    while (fin >> junk >> num)
        data.push_back(num); // data[0] will be the first data. 
                             // data[1] will be the second data and so on.
    
    //////////// the sorting part ////////////////
    tmusg.periodStart();
    SortTool NTUSortTool; 

    if(!strcmp(argv[1],"-IS")) {
        NTUSortTool.InsertionSort(data);
    }
    else if(!strcmp(argv[1],"-MS")) {
        NTUSortTool.MergeSort(data);
    }
    else if(!strcmp(argv[1],"-QS")) {
        NTUSortTool.QuickSort(data);
    }
    else {
        help_message();
        return 0;
    }

    tmusg.getPeriodUsage(stat);
    cout <<"The total CPU time: " << (stat.uTime + stat.sTime) / 1000.0 << "ms" << endl;
    cout <<"memory: " << stat.vmPeak << "KB" << endl; // print peak memory

    //////////// write the output file ///////////
    fout << "# " << data.size() << " data points" <<endl;
    fout << "# index number" << endl;
    for (int i = 0; i < data.size(); i++)
        fout << i << " " <<data[i] << endl;
    fin.close();
    fout.close();
    return 0;
}
예제 #2
0
int main(int argc, char* argv[])
{
    if(argc != 4) {
       help_message();
       return 0;
    }
    CommonNs::TmUsage tmusg;
    CommonNs::TmStat stat;

    //////////// read the input file /////////////
    
    char buffer[200];
    fstream fin(argv[2]);
    
    fin.getline(buffer,200);
    fin.getline(buffer,200);
    int ID, x, y, z;
    vector<Doll*> Darray(0);
    vector<Doll*> Sequence(0);
    while (fin >> ID >> x >> y >> z) {
        Darray.push_back(new Doll(ID,x,y,z));

    }

    //////////// find the Matryoshka sequence ////
    tmusg.periodStart();

    if(strcmp(argv[1], "-GD") == 0) {
        Greedy(Darray, Sequence);
    }
    else if(strcmp(argv[1], "-TD") == 0) {
        TopDown(Darray, Sequence);
    }
    else if(strcmp(argv[1], "-BU") == 0) {
        BottomUp(Darray, Sequence);
        
    }
    else {
        help_message();
        return 0;
    }

    tmusg.getPeriodUsage(stat);

    //////////// write the output file ///////////
    
    ofstream fout(argv[3]);
    fout << "# m = " << Sequence.size() << endl;
    fout << "# ID x  y  z" << endl;
    for(int i=0; i<Sequence.size(); i++) {
        fout << Sequence[i]->getID() << "  " << Sequence[i]->getX() << "  ";
        fout << Sequence[i]->getY() << "  " << Sequence[i]->getZ() << endl;
    }
    
    // Place print the following message in the output file

    fout <<"# run time = " << (stat.uTime + stat.sTime) / 1000000.0 << "sec" << endl;
    fout <<"# memory = " << stat.vmPeak / 1000.0 << "MB" << endl;

    return 0;
}