当前位置: 首页>>代码示例>>C++>>正文


C++ IloModel::end方法代码示例

本文整理汇总了C++中IloModel::end方法的典型用法代码示例。如果您正苦于以下问题:C++ IloModel::end方法的具体用法?C++ IloModel::end怎么用?C++ IloModel::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IloModel的用法示例。


在下文中一共展示了IloModel::end方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

 /** Destructor. */
 ~Worker() {
    if ( handle ) {
       handle.kill();
       handle.join();
    }
    if ( cplex.getImpl() ) {
       cplex.userfunction(USERACTION_REMOVECALLBACK, 0, NULL, 0, 0, NULL);
       cplex.end();
    }
    rng.end();
    x.end();
    obj.end();
    model.end();
 }
开发者ID:renvieir,项目名称:ioc,代码行数:15,代码来源:iloparmipopt.cpp

示例2: main

int main()
{
	clock_t start,finish;
	double totaltime;
	start=clock();	
	
	try{
/************************************变量初始化******************************************/		
		for(IloInt i=0;i<NG;++i)
		{
			P[i]=IloNumVarArray(env,NT,0,IloInfinity,ILOFLOAT);
			S3[i]=IloNumVarArray(env,NT,0,IloInfinity,ILOFLOAT);
			deta[i]=10;
		}		
/************************************数据读取******************************************/
		ifstream input_wind("wind_scenarios.txt",ios::in);//误差场景,由蒙特卡洛方法生成
		output<<endl<<"error sceanrios:"<<endl;
		for(IloInt w=0;w<NW;++w)
		{
			Pwind[w]=IloNumArray(env,NT);
			for(IloInt t=0;t<NT;++t)
			{
				input_wind>>Pwind[w][t];
				output<<Pwind[w][t]<<"   ";
			}
			output<<endl;
		}
		input_wind.close();

		ifstream input_commitment("uc.txt",ios::in);//机组启停状态
		output<<endl<<"Unit State:"<<endl;
		if(!input_commitment)
		{
			cerr<<"uc.txt is not exist!!!"<<endl;
		}
		for(IloInt i=0;i<NG;++i)
		{
			I[i]=IloNumArray(env,NT);
			for(IloInt t=0;t<NT;++t)
			{
				input_commitment>>I[i][t];
				output<<I[i][t]<<"  ";
			}
			output<<endl;
		}
		input_commitment.close();
		
		ifstream input_preoutput("Ppower.txt",ios::in);//预测场景下出力
		output<<endl<<"power of forecast sceanrios:"<<endl;
		if(!input_preoutput)
		{
			cerr<<"Ppower.txt is not exist"<<endl;
		}
		for(IloInt i=0;i<NG;++i)
		{
			Pre[i]=IloNumArray(env,NT);
			for(IloInt t=0;t<NT;++t)
			{
				input_preoutput>>Pre[i][t];
				output<<Pre[i][t]<<"  ";
			}
			output<<endl;
		}
		input_preoutput.close();

		ifstream input_load("load.txt",ios::in);//读取负荷信息
		output<<endl<<"Load:"<<endl;
		if(!input_load)
		{
			cerr<<"load.txt is not exist!!!"<<endl;
		}
		for(IloInt t=0; t<NT; ++t)
		{
			input_load>>Pload[t];
			output<<Pload[t]<<"   ";
		}
		input_load.close();
				
		ifstream input_BFile("Brach_File.txt",ios::in);//读取风电支路信息:起点,终点,电阻,电抗以及潮流上限
		output<<endl<<"Information of Branch:"<<endl;
		if(!input_BFile)
		{	
			output<<"Brach_File.txt is not exist!!!"<<endl;
		}
		for(IloInt k=0; k<Branch; ++k)
		{	
			Info_Branch[k]=IloNumArray(env,5);
			for(IloInt h=0; h<5; ++h)
			{
				input_BFile>>Info_Branch[k][h];
				output<<Info_Branch[k][h]<<"   ";
			}
			output<<endl;
		}
		input_BFile.close();
		
		ifstream input_unitinfo("unit_information.txt",ios::in);//读入机组信息
		output<<endl<<"Unit Information:"<<endl;
		if(!input_unitinfo)
		{
//.........这里部分代码省略.........
开发者ID:zclzqbx,项目名称:walker-tmp,代码行数:101,代码来源:scenario.check.cpp

示例3: main

int main()
{
	clock_t start,finish;
	double totaltime;
	start=clock();

	try
	{
		output<<">>>>>>>>>>>>>>数据区<<<<<<<<<<<<<<<"<<endl;		
		define_data(env);//首先初始化全局变量
		output<<">>>>>>>>>>>>>>数据区结束<<<<<<<<<<<<<<<"<<endl;	
/*************************************************************目标函数*******************************************************/
		IloNumExpr Cost(env);

		for(IloInt i=0; i<NG; ++i) //运行成本及其线性化(青华姐论文)
			for(IloInt l=0; l<NL; ++l)
				for(IloInt t=0; t<NT; ++t)
				{
					Master_Model.add(Deta[i][l][t]<=Z[i][l+1]-Z[i][l]);
				}
		for(IloInt i=0; i<NG; ++i)
			for(IloInt t=0; t<NT; ++t)
			{
				IloNumExpr Deta_Sum(env);
				for(IloInt l=0; l<NL; ++l)
				{
					Deta_Sum+=Deta[i][l][t];
				}
				Master_Model.add(P[i][t]==Deta_Sum+Unit[i][1]*I[i][t]);
				Deta_Sum.end();
			}			
		for(IloInt i=0; i<NG; ++i)
		{
			for(IloInt t=0; t<NT; ++t)
			{
				IloNumExpr f1(env);
				f1+=(Unit[i][10]+Unit[i][9]*Unit[i][1]+Unit[i][8]*Unit[i][1]*Unit[i][1])*I[i][t];
				for(IloInt l=0; l<NL; ++l)
					f1+=Betaa[i][l]*Deta[i][l][t];
				Cost+=f1*Unit[i][11];
				f1.end();
			}
		}

		for(IloInt i=0; i<NG; ++i)//开机成本
			for(IloInt t=1; t<NT; ++t)
			{
				Cost+=Unit[i][11]*Unit[i][7]*I[i][t]*(1-I[i][t-1]);
			}

		for(IloInt i=0; i<NG; ++i)//停机成本
			for(IloInt t=1; t<NT; ++t)
			{
				Cost+=Unit[i][11]*Unit[i][7]*I[i][t-1]*(1-I[i][t]);
			}
		Master_Model.add(IloMinimize(env,Cost));
/********************************************************机组出力上下限约束**************************************************/
		for(IloInt i=0; i<NG; ++i)
			for(IloInt t=0; t<NT; ++t)
			{
				Master_Model.add(P[i][t]<=Unit[i][2]*I[i][t]);//最好分开写
				Master_Model.add(P[i][t]>=Unit[i][1]*I[i][t]);
			}
/*********************************************************机组爬坡约束******************************************************/
		for(IloInt i=0; i<NG; ++i)
			for(IloInt t=1; t<NT; ++t)
			{
				Master_Model.add(P[i][t]-P[i][t-1]<=(1-I[i][t]*(1-I[i][t-1]))*Unit[i][5]+I[i][t]*(1-I[i][t-1])*Unit[i][1]);
				Master_Model.add(P[i][t-1]-P[i][t]<=(1-I[i][t-1]*(1-I[i][t]))*Unit[i][6]+I[i][t-1]*(1-I[i][t])*Unit[i][1]);
			}
/*********************************************************机组功率平衡约束**************************************************/
		for(IloInt t=0; t<NT; ++t)
		{
			IloNumExpr fire(env);
			IloNum wind(0);
			for(IloInt i=0; i<NG; ++i)
			{
				fire+=P[i][t];
			}
			
			for(IloInt w=0;w<NW;++w)
			{
				wind+=Pwind[t][w];
			}
			
			Master_Model.add(fire==Pload[t]-wind);
			fire.end();
		}
/**********************************************************备用约束********************************************************/
		for(IloInt t=0; t<NT; ++t) //条件不全
		{
			IloNumExpr expr(env);
			for(IloInt i=0; i<NG; ++i)
			{
				expr+=Unit[i][2]*I[i][t];
			}
			Master_Model.add(expr>=R[t]+Pload[t]);
		}
/**********************************************************安全约束********************************************************/
		////求每个节点的注入功率
//.........这里部分代码省略.........
开发者ID:zclzqbx,项目名称:walker-tmp,代码行数:101,代码来源:scuc_v1.cpp

示例4: main

/********************************************程序入口**********************************************/
int main()
{
	clock_t start,finish;
	double totaltime;
	start=clock();
	time_t nowTime=time(0);
	struct tm* nowTimeStruct=localtime(&nowTime);//时间统计及打印系统时间
	output<<"系统当前时间:"<<1900+nowTimeStruct->tm_year<<"."<<nowTimeStruct->tm_mon+1<<"."<<
		nowTimeStruct->tm_mday<<"  "<<nowTimeStruct->tm_hour<<":"<<nowTimeStruct->tm_min<<":"
		<<nowTimeStruct->tm_sec<<endl;

	try
	{
		output<<">>>>>>>>>>>>>>>>>>>>>>>>>数据区<<<<<<<<<<<<<<<<<<<<"<<endl;
		define_data(env);//首先初始化全局变量
		output<<">>>>>>>>>>>>>>>>>>>>>>>>>/数据区<<<<<<<<<<<<<<<<<<<"<<endl<<endl;
/******************************************主问题目标函数*****************************************************/
		IloNumExpr Cost(env);
		
		for(IloInt i=0;i<NG;++i)//运行成本及其线性化
			for(IloInt l=0;l<NL;++l)
				for(IloInt t=0;t<NT;++t)
				{
					Master_Model.add(Deta[i][l][t]<=Z[i][l+1]-Z[i][l]);
				}
		for(IloInt i=0;i<NG;++i)
			for(IloInt t=0;t<NT;++t)
			{
				IloNumExpr Deta_Sum(env);
				for(IloInt l=0;l<NL;++l)
				{
					Deta_Sum+=Deta[i][l][t];
				}
				Master_Model.add(P[i][t]==Deta_Sum+Unit[i][1]*I[i][t]);
				Deta_Sum.end();
			}
		for(IloInt i=0;i<NG;++i)
		{
			for(IloInt t=0;t<NT;++t)
			{
				IloNumExpr f1(env);
				f1+=(Unit[i][10]+Unit[i][9]*Unit[i][1]+Unit[i][8]*Unit[i][1]*Unit[i][1])*I[i][t];
				for(IloInt l=0;l<NL;++l)
					f1+=Betaa[i][l]*Deta[i][l][t];
				Cost+=f1*Unit[i][11];
				f1.end();
			}
		}
		
		for(IloInt i=0; i<NG; ++i)//开机成本
			for(IloInt t=1; t<NT; ++t)
			{
				Cost+=Unit[i][11]*Unit[i][7]*I[i][t]*(1-I[i][t-1]);
			}
			
		for(IloInt i=0; i<NG; ++i)//停机成本
			for(IloInt t=1; t<NT; ++t)
			{
				Cost+=Unit[i][11]*Unit[i][7]*I[i][t-1]*(1-I[i][t]);
			}
		
		Master_Model.add(IloMinimize(env,Cost));
		Cost.end();
/*******************************************机组出力上下限约束*********************************************/
		for(IloInt i=0; i<NG; ++i)
			for(IloInt t=0; t<NT; ++t)
			{
				Master_Model.add(P[i][t]<=Unit[i][2]*I[i][t]);
				Master_Model.add(P[i][t]>=Unit[i][1]*I[i][t]);
			}
/*********************************************机组爬坡约束**************************************************/
		for(IloInt i=0; i<NG; ++i)
			for(IloInt t=1; t<NT; ++t)
			{
				Master_Model.add(P[i][t]-P[i][t-1]<=(1-I[i][t]*(1-I[i][t-1]))*
											Unit[i][5]+I[i][t]*(1-I[i][t-1])*Unit[i][1]);
				Master_Model.add(P[i][t-1]-P[i][t]<=(1-I[i][t-1]*(1-I[i][t]))*
											Unit[i][6]+I[i][t-1]*(1-I[i][t])*Unit[i][1]);
			}
/**********************************************机组功率平衡约束**********************************************/
		for(IloInt t=0; t<NT; ++t)
		{
			IloNumExpr fire(env);
			IloNum wind(0);
			for(IloInt i=0; i<NG; ++i)
			{
				fire+=P[i][t];
			}
			for(IloInt w=0;w<NW;++w)
			{
				wind+=Pwind[t][w];
			}
			Master_Model.add(fire==Pload[t]-wind);
			fire.end();
		}
/*************************************************备用约束************************************************/
		for(IloInt t=0; t<NT; ++t)
		{
			IloNumExpr expr(env);
//.........这里部分代码省略.........
开发者ID:zclzqbx,项目名称:scenariosOrder,代码行数:101,代码来源:fixedWind_uc_problem.cpp

示例5: main

/**************************************************程序入口****************************************************/
int main()
{
	clock_t start,finish;
	double totaltime;
	start=clock();
	
	try
	{
		define_data(env);//首先初始化全局变量		
		IloInvert(env,B0,B0l,Node-1);//求逆矩阵
/*************************************************************主问题目标函数*******************************************************/
		IloNumExpr Cost(env);
		for(IloInt w=0;w<NW;++w)
		{
			Cost+=detaPw[w];
		}		
		 Master_Model.add(IloMinimize(env,Cost));
		//Master_Model.add(IloMaximize(env,Cost));//目标函数二先一
		Cost.end();
/********************************************************机组出力上下限约束**************************************************/
		IloNumExpr expr1(env),expr2(env);
		for(IloInt i=0;i<NG;++i)
		{
			expr1+=detaP[i];
		}
		for(IloInt w=0;w<NW;++w)
		{
			expr2+=detaPw[w];
		}
		Master_Model.add(expr1==expr2);
		expr1.end();
		expr2.end();
		
		for(IloInt i=0;i<NG;++i)
		{
			Master_Model.add(detaP[i]>=Unit[i][1]*u[i]-P1[i]);
			Master_Model.add(detaP[i]<=Unit[i][2]*u[i]-P1[i]);
			
			Master_Model.add(detaP[i]>=-detaa[i]);
			Master_Model.add(detaP[i]<=detaa[i]);
		}
		
		IloNumExprArray detaP_node(env,Node-1),detaPw_node(env,Node-1);
		IloNumExprArray Theta(env,Node);
		
		for(IloInt b=0;b<Node-1;++b)
		{
			detaP_node[b]=IloNumExpr(env);
			detaPw_node[b]=IloNumExpr(env);
			IloInt i=0;
			for(;i<NG;++i)
			{
				if(Unit[i][0]==b-1)break;
			}
			if(i<NG)
			{
				detaP_node[b]+=detaP[i];
			}
			else
			{
				detaP_node[b]+=0;
			}
			
			
			if(Sw[b]>=0)
			{
				detaPw_node[b]+=detaPw[ Sw[b] ];
			}
			else
			{
				detaPw_node[b]+=0;
			}
		}
		
		for(IloInt b=0;b<Node-1;++b)
		{
			Theta[b]=IloNumExpr(env);
			for(IloInt k=0;k<Node-1;++k)
			{			
				Theta[b]+=B0l[b][k]*(detaP_node[k]+detaPw_node[k]);	
			}
		}
		Theta[Node-1]=IloNumExpr(env);
		
		for(IloInt h=0;h<Branch;++h)
		{
			IloNumExpr exprTheta(env);//莫明其妙的错误
			exprTheta+=(Theta[(IloInt)Info_Branch[h][0]-1]-Theta[(IloInt)Info_Branch[h][1]-1]);
			
			Master_Model.add(exprTheta<=Info_Branch[h][3]*(Info_Branch[h][4]-PL[h]));			
			Master_Model.add(exprTheta>=Info_Branch[h][3]*(-Info_Branch[h][4]-PL[h]));
			exprTheta.end();
			//两个相减的节点顺序没有影响么?
		}
		Theta.end();
		detaP_node.end();
		detaPw_node.end();
		
		Master_Cplex.extract(Master_Model);
//.........这里部分代码省略.........
开发者ID:zclzqbx,项目名称:walker-tmp,代码行数:101,代码来源:adjustment.cpp

示例6: main

/**************************************************程序入口****************************************************/
int main()
{
	clock_t start,finish;
	double totaltime;
	start=clock();
	
	try
	{
		define_data(env);//首先初始化全局变量
/*************************************************************主问题目标函数*******************************************************/
		IloNumExpr Cost(env);
		
		for(IloInt i=0;i<NG;++i)//运行成本及其线性化
			for(IloInt l=0;l<NL;++l)
				for(IloInt t=0;t<NT;++t)
				{
					Master_Model.add(Deta[i][l][t]<=Z[i][l+1]-Z[i][l]);
				}
		for(IloInt i=0;i<NG;++i)
			for(IloInt t=0;t<NT;++t)
			{
				IloNumExpr Deta_Sum(env);
				for(IloInt l=0;l<NL;++l)
				{
					Deta_Sum+=Deta[i][l][t];
				}
				Master_Model.add(P[i][t]==Deta_Sum+Unit[i][1]*I[i][t]);
				Deta_Sum.end();
			}
		for(IloInt i=0;i<NG;++i)
		{
			for(IloInt t=0;t<NT;++t)
			{
				IloNumExpr f1(env);
				f1+=(Unit[i][10]+Unit[i][9]*Unit[i][1]+Unit[i][8]*Unit[i][1]*Unit[i][1])*I[i][t];
				for(IloInt l=0;l<NL;++l)
					f1+=Betaa[i][l]*Deta[i][l][t];
				Cost+=f1*Unit[i][11];
				f1.end();
			}
		}
		
		for(IloInt i=0; i<NG; ++i)//开机成本
			for(IloInt t=1; t<NT; ++t)
			{
				Cost+=Unit[i][11]*Unit[i][7]*I[i][t]*(1-I[i][t-1]);
			}
			
		for(IloInt i=0; i<NG; ++i)//停机成本
			for(IloInt t=1; t<NT; ++t)
			{
				Cost+=Unit[i][11]*Unit[i][7]*I[i][t-1]*(1-I[i][t]);
			}
		
		Master_Model.add(IloMinimize(env,Cost));
		Cost.end();
/********************************************************机组出力上下限约束**************************************************/
		for(IloInt i=0; i<NG; ++i)
			for(IloInt t=0; t<NT; ++t)
			{
				Master_Model.add(P[i][t]<=Unit[i][2]*I[i][t]);
				Master_Model.add(P[i][t]>=Unit[i][1]*I[i][t]);
			}
/*********************************************************机组爬坡约束******************************************************/
		for(IloInt i=0; i<NG; ++i)
			for(IloInt t=1; t<NT; ++t)
			{
				Master_Model.add(P[i][t]-P[i][t-1]<=(1-I[i][t]*(1-I[i][t-1]))*Unit[i][5]+I[i][t]*(1-I[i][t-1])*Unit[i][1]);
				Master_Model.add(P[i][t-1]-P[i][t]<=(1-I[i][t-1]*(1-I[i][t]))*Unit[i][6]+I[i][t-1]*(1-I[i][t])*Unit[i][1]);
			}
/*********************************************************机组功率平衡约束**************************************************/
		for(IloInt t=0; t<NT; ++t)
		{
			IloNumExpr fire(env);
			IloNum wind(0);
			for(IloInt i=0; i<NG; ++i)
			{
				fire+=P[i][t];
			}
			for(IloInt w=0;w<NW;++w)
			{
				wind+=Pwind[t][w];
			}
			Master_Model.add(fire==Pload[t]-wind);
			fire.end();
		}
/**********************************************************备用约束********************************************************/
		for(IloInt t=0; t<NT; ++t) 
		{
			IloNumExpr expr(env);
			for(IloInt i=0;i<NG;++i)
			{
				expr+=Unit[i][2]*I[i][t];
			}
			Master_Model.add(expr>=Pload[t]+R[t]);
			expr.end();
		}
/***********************************************************最小开机时间约束*************************************************/
		for(IloInt i=0; i<NG; ++i)
//.........这里部分代码省略.........
开发者ID:zclzqbx,项目名称:walker-tmp,代码行数:101,代码来源:benders_v3.cpp

示例7: Worker

   /** Create a new worker.
    * The constructor mainly does the following:
    * - create an IloCplex instance that refers to a remote worker,
    * - load the model in <code>modelfile</code>,
    * - setup parameters depending on this worker's index,
    * - start an asynchronous solve.
    * If anything fails then an exception will be thrown.
    * @param env The environment used for instantiating Ilo* objects.
    * @param i The index of the worker to be created. This also
    *          determines the parameter settings to use in this worker.
    * @param s  A pointer to the global solve state.
    * @param transport  The transport name for the IloCplex constructor.
    * @param argc       The argument count for the IloCplex constructor.
    * @param argv       The array of transport arguments for the IloCplex
    *                   constructor.
    * @param modelfile  Name of the model to be loaded into the worker.
    * @param output     The output mode.
    * @param objdiff    The minimal difference between so that two
    *                   consecutive objective function values are considered
    *                   different.
    */
   Worker(IloEnv env, int i, SolveState *s, char const *transport,
          int argc, char const **argv, char const *modelfile,
          OUTPUT output, double objdiff)
      : idx(i), state(s), model(env), cplex(0), handle(0),
        primal(IloInfinity), dual(-IloInfinity),
        obj(env), x(env), rng(env), infoHandler(this), outb(idx), outs(&outb)
   {
      try {
         // Create remote object, setup output and load the model.
         cplex = IloCplex(model, transport, argc, argv);
         switch (output) {
         case OUTPUT_SILENT:
            // Disable output on the output and warning stream.
            cplex.setOut(env.getNullStream());
            cplex.setWarning(env.getNullStream());
            break;
         case OUTPUT_PREFIXED:
            // Redirect output to our custom stream.
            cplex.setOut(outs);
            cplex.setWarning(outs);
            break;
         case OUTPUT_LOG:
            // Nothing to do here. By default output is enabled.
            break;
         }
         cplex.importModel(model, modelfile, obj, x, rng);
         if ( obj.getSense() == IloObjective::Minimize ) {
            primal = -IloInfinity;
            dual = IloInfinity;
         }

         // We set the thread count for each solver to 1 so that we do not
         // run into problems if multiple solves are performed on the same
         // machine.
         cplex.setParam(IloCplex::Param::Threads, 1);
         // Each worker runs with a different random seed. This way we
         // get different paths through the tree even if the other
         // parameter settings are the same.
         cplex.setParam(IloCplex::Param::RandomSeed, idx);
         // Apply parameter settings.
         for (class ParamValue const *vals = settings[idx % NUMSETTINGS].values;
              vals->isValid(); ++vals)
            vals->apply(cplex);

         // Install callback and set objective change.
         int status = cplex.userfunction (USERACTION_ADDCALLBACK,
                                          0, NULL, 0, 0, NULL);
         if ( status )
            throw status;
         IloCplex::Serializer s;
         s.add(objdiff);
         status = cplex.userfunction (USERACTION_CHANGEOBJDIFF,
                                      s.getRawLength(), s.getRawData(),
                                      0, 0, NULL);
         if ( status )
            throw status;

         // Register the handler that will process info messages sent
         // from the worker.
         cplex.setRemoteInfoHandler(&infoHandler);

         // Everything is setup. Launch the asynchronous solve.
         handle = cplex.solve(true);
      } catch (...) {
         // In case of an exception we need to take some special
         // cleanup actions. Note that if we get here then the
         // solve cannot have been started and we don't need to
         // kill or join the asynchronous solve.
         if ( cplex.getImpl() )
            cplex.end();
         rng.end();
         x.end();
         obj.end();
         model.end();
         throw;
      }
   }
开发者ID:renvieir,项目名称:ioc,代码行数:98,代码来源:iloparmipopt.cpp

示例8: main

/**************************************************程序入口****************************************************/
int main()
{
	clock_t start,finish;
	double totaltime;
	start=clock();
	time_t nowTime=time(0);
	struct tm* nowTimeStruct=localtime(&nowTime);//打印系统时间
	// output<<"系统当前时间:"<<1900+nowTimeStruct->tm_year<<"."<<nowTimeStruct->tm_mon+1<<"."<<
		// nowTimeStruct->tm_mday<<"  "<<nowTimeStruct->tm_hour<<":"<<nowTimeStruct->tm_min<<":"<<nowTimeStruct->tm_sec<<endl;
	
	try
	{
		// output<<">>>>>>>>>>>>>>>>>>>>>>>>>数据区<<<<<<<<<<<<<<<<<<<<"<<endl;
		define_data(env);//首先初始化全局变量
		// output<<">>>>>>>>>>>>>>>>>>>>>>>>>/数据区<<<<<<<<<<<<<<<<<<<"<<endl<<endl;
		
		IloInvert(env,B0,B0l,Node-1);//求逆矩阵
		
		//在此创建两种形式的目标函数
		IloNumExpr Cost(env);//目标函数			
		for(IloInt w=0;w<NW;++w)
		{
			Cost+=detaPw[w];
		}
		IloObjective min(env,Cost,IloObjective::Sense::Minimize,"min");
		IloObjective max(env,Cost,IloObjective::Sense::Maximize,"max");	
		Master_Model.add(min);
		// Master_Model.add(IloMaximize(env,Cost));//目标函数二选一
		Cost.end();

		IloNumExpr expr1(env),expr2(env);//功率平衡约束
		for(IloInt i=0;i<NG;++i)
		{
			expr1+=detaP[i];
		}
		for(IloInt w=0;w<NW;++w)
		{
			expr2+=detaPw[w];
		}
		Master_Model.add(expr1+expr2==0);
		expr1.end();
		expr2.end();
		
		for(IloInt i=0;i<NG;++i)//机组可调节范围
		{
			Master_Model.add(detaP[i]>=Unit[i][1]*u[i]-P1[i]);
			Master_Model.add(detaP[i]<=Unit[i][2]*u[i]-P1[i]);
			
			Master_Model.add(detaP[i]>=-detaa[i]);
			Master_Model.add(detaP[i]<=detaa[i]);
		}
		
		IloNumExprArray detaP_node(env,Node-1),detaPw_node(env,Node-1);//安全约束,实际上安全约束影响不大
		IloNumExprArray Theta(env,Node);
		
		for(IloInt b=0;b<Node-1;++b)
		{
			detaP_node[b]=IloNumExpr(env);
			detaPw_node[b]=IloNumExpr(env);
			IloInt i=0;
			for(;i<NG;++i)
			{
				if(Unit[i][0]==b-1)break;
			}
			
			if(i<NG)
			{
				detaP_node[b]+=detaP[i];
			}	
			
			if(Sw[b]>=0)
			{
				detaPw_node[b]+=detaPw[ Sw[b] ];
			}
		}
		
		for(IloInt b=0;b<Node-1;++b)
		{
			Theta[b]=IloNumExpr(env);
			for(IloInt k=0;k<Node-1;++k)
			{			
				Theta[b]+=B0l[b][k]*(detaP_node[k]+detaPw_node[k]);	
			}
		}
		Theta[Node-1]=IloNumExpr(env);
		
		for(IloInt h=0;h<Branch;++h)
		{
			IloNumExpr exprTheta(env);//莫明其妙的错误
			exprTheta+=(Theta[(IloInt)Info_Branch[h][0]-1]-Theta[(IloInt)Info_Branch[h][1]-1]);
			
			Master_Model.add(exprTheta<=Info_Branch[h][3]*(Info_Branch[h][4]-PL[h]));			
			Master_Model.add(exprTheta>=Info_Branch[h][3]*(-Info_Branch[h][4]-PL[h]));
			exprTheta.end();
			//两个相减的节点顺序没有影响么?
		}
		Theta.end();
		detaP_node.end();
		detaPw_node.end();
//.........这里部分代码省略.........
开发者ID:zclzqbx,项目名称:scenariosOrder,代码行数:101,代码来源:adjustment_area_v1.cpp


注:本文中的IloModel::end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。