コード例 #1
0
int GLPKLoadVariables(MFAVariable* InVariable, bool RelaxIntegerVariables,bool UseTightBounds) {
	if (GLPKModel == NULL) {
		FErrorFile() << "Could not add variable because GLPK object does not exist." << endl;
		FlushErrorFile();
		return FAIL;
	}

	int NumColumns = glp_get_num_cols(GLPKModel);

	if (InVariable->Index >= NumColumns) {
		glp_add_cols(GLPKModel, 1);
		string Name = GetMFAVariableName(InVariable);
		char* Temp = new char[Name.length()+1];
		strcpy(Temp,Name.data());
		glp_set_col_name(GLPKModel,InVariable->Index+1,Temp);
	}


	double LowerBound = InVariable->LowerBound;
	double UpperBound = InVariable->UpperBound;
	if (UseTightBounds) {
		LowerBound = InVariable->Min;
		UpperBound = InVariable->Max;
	}
	if (LowerBound != UpperBound) {
		glp_set_col_bnds(GLPKModel, InVariable->Index+1, GLP_DB, InVariable->LowerBound, InVariable->UpperBound);
	} else {
		glp_set_col_bnds(GLPKModel, InVariable->Index+1, GLP_FX, InVariable->LowerBound, InVariable->UpperBound);
	}

	if (InVariable->Binary && !RelaxIntegerVariables) {
		//glp_set_class(GLPKModel, GLP_MIP); There is no equivalent in the new API
		glp_set_col_kind(GLPKModel, InVariable->Index+1,GLP_IV);
	}

	return SUCCESS;
}
コード例 #2
0
ファイル: CPLEXapi.cpp プロジェクト: aabest/Model-SEED-core
int CPLEXLoadVariables(MFAVariable* InVariable, bool RelaxIntegerVariables,bool UseTightBounds) {
	int Status = 0;
	
	//First I check the number of columns. If it's larger than the index, then this variable already exists and is only being changed
	int NumberColumns = CPXgetnumcols (CPLEXenv, CPLEXModel);
	if (NumberColumns <= InVariable->Index) {
		string StrName = GetMFAVariableName(InVariable);
		
		double* LB = new double;
		LB[0] = InVariable->LowerBound;
		double* UB = new double;
		UB[0] = InVariable->UpperBound;
		if (UseTightBounds) {
			LB[0] = InVariable->Min;
			UB[0] = InVariable->Max;
		}
		double* Obj = new double;
		Obj[0] = 0;
		char* Temp = new char;
		char** Name = new char*;
		Name[0] = new char[StrName.length()+1];
		strcpy(Name[0],StrName.data());
		
		if (InVariable->Binary && !RelaxIntegerVariables) {
			Temp[0] = CPX_BINARY;
			Status = CPXnewcols (CPLEXenv, CPLEXModel, 1, Obj, LB, UB, Temp, Name);
		} else if (InVariable->Integer && !RelaxIntegerVariables) {
			Temp[0] = CPX_INTEGER;
			Status = CPXnewcols (CPLEXenv, CPLEXModel, 1, Obj, LB, UB, Temp, Name);
		} else {
			Temp[0] = CPX_CONTINUOUS;
			Status = CPXnewcols (CPLEXenv, CPLEXModel, 1, Obj, LB, UB, Temp, Name);
		}

		delete LB;
		delete UB;
		delete Obj;
		delete Temp;
		delete [] Name[0];
		delete Name;

		if (Status ) {
			FErrorFile() << "Could not add variable " << InVariable->Index << endl;
			FlushErrorFile();
			return FAIL;
		}
	} else {
		double* Bounds = new double[2];
		Bounds[0] = InVariable->LowerBound;
		Bounds[1] = InVariable->UpperBound;
		
		int* Indices = new int[2];
		Indices[0] = InVariable->Index;
		Indices[1] = InVariable->Index;

		Status = CPXchgbds (CPLEXenv, CPLEXModel, 2, Indices, "LU", Bounds);
		
		delete [] Bounds;
		delete [] Indices;

		if (Status) {
			FErrorFile() << "Could not change bounds on variable " << InVariable->Index << endl;
			FlushErrorFile();
			return FAIL;
		}
	}

	return SUCCESS;
}