code/instance.hpp
// Construct an instance from an instance file.
// <Param>
//		string filePath: the path of the instance file
// </Param>
Construct an instance from an instance file.

string filePath: the path of the instance file

Construct an instance from an instance file . string filePath : the path of the instance file
Instance::Instance(string filePath) {
    FILE* fp = fopen(filePath.c_str(), "r");
    if (fp == nullptr) {
    	cout << "Failed to open file: " << filePath << endl;
	} else {
	    int temp = 0;
	    cout << "read facility num...";
	    fscanf(fp, "%d", &(temp));
	    this->facility_num = temp;
	    cout << "done!" << endl;
	    cout << "read customer num...";
	    fscanf(fp, "%d", &(temp));
	    this->customer_num = temp;
	    cout << "done!" << endl;
	    cout << "read facility capicity and open cost...";
	    for (int i = 0; i < this->facility_num; ++i) {
	        fscanf(fp, "%d", &temp);
	        this->capicity.push_back(temp);
	        fscanf(fp, "%d", &temp);
	        this->open_cost.push_back(temp);
	    }
		cout << "done!" << endl;
		cout << "read customer demand...";
	    for (int i = 0; i < this->customer_num; ++i) {
	        fscanf(fp, "%d", &temp);
	        this->demand.push_back(temp);
	    }
	    cout << "done!" << endl;
		cout << "read allocation cost...";
	    this->allocate_cost.resize(this->facility_num);
	    for (int i = 0; i < this->facility_num; ++i) {
	        this->allocate_cost[i].resize(this->customer_num);
	        for (int j = 0; j < this->customer_num; ++j) {
	            fscanf(fp, "%d", &temp);
	            this->allocate_cost[i][j] = temp;
	        }
	    }
	    cout << "done!" << endl;
	    fclose(fp);
	}
}
Instance :: Instance ( string filePath ) { FILE * fp = fopen ( filePath . c_str ( ) , " " ) ; if ( fp == nullptr ) { cout << " " << filePath << endl ; } else { int temp = 0 ; cout << " " ; fscanf ( fp , " " , & ( temp ) ) ; this -> facility_num = temp ; cout << " " << endl ; cout << " " ; fscanf ( fp , " " , & ( temp ) ) ; this -> customer_num = temp ; cout << " " << endl ; cout << " " ; for ( int i = 0 ; i < this -> facility_num ; ++ i ) { fscanf ( fp , " " , & temp ) ; this -> capicity . push_back ( temp ) ; fscanf ( fp , " " , & temp ) ; this -> open_cost . push_back ( temp ) ; } cout << " " << endl ; cout << " " ; for ( int i = 0 ; i < this -> customer_num ; ++ i ) { fscanf ( fp , " " , & temp ) ; this -> demand . push_back ( temp ) ; } cout << " " << endl ; cout << " " ; this -> allocate_cost . resize ( this -> facility_num ) ; for ( int i = 0 ; i < this -> facility_num ; ++ i ) { this -> allocate_cost [ i ] . resize ( this -> customer_num ) ; for ( int j = 0 ; j < this -> customer_num ; ++ j ) { fscanf ( fp , " " , & temp ) ; this -> allocate_cost [ i ] [ j ] = temp ; } } cout << " " << endl ; fclose ( fp ) ; } }
Construct an instance from an instance file.
Construct an instance from an instance file .
// read facility capicity // read facility open cost // read customer demand // read allocating cost