跳至主内容
框架 无框架

宏ILOCPCONSTRAINTWRAPPER0

定义文件: ilcp/cpext.h
ILOCPCONSTRAINTWRAPPER0(_this, 求解器)
ILOCPCONSTRAINTWRAPPER1(_this, solver,t1,a1)
ILOCPCONSTRAINTWRAPPER2(_this, solver,t1,a1,t2 a2)
ILOCPCONSTRAINTWRAPPER3(_this, solver,t1,a1,t2,a2,t3 a3)
ILOCPCONSTRAINTWRAPPER4(_this, solver,t1,a1,t2,a2,t3,a3,t4 a4)
ILOCPCONSTRAINTWRAPPER5(_this, solver,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5)
ILOCPCONSTRAINTWRAPPER6(_this, solver,t1,a1,t2,a2,t3,a3,t4,a4,t5,a5,t6 a6)
宏,用于封装新的约束类。

这个宏会定义名为 _thisI 的约束类,其中有 n 个数据成员。 当 n 大于零时,数据成员的类型和名称必须以参数形式提供给这个宏。 每个数据成员由其类型 "ti和名称 "ai 定义。

由于参数 "this用于命名约束类,因此无法对多个约束使用相同的名称。

You can use the macro ILOCPCONSTRAINTWRAPPER to wrap an existing instance of IlcConstraint when you want to use it within IBM® ILOG® Concert Technology model objects. 要以这种方式使用 "IlcConstraint实例,您需要遵循以下步骤:

  1. 使用宏将 " IlcConstraint实例封装到 " IloConstraint实例中。
  2. Extract your model and model objects for an instance of IloCP by calling the member function IloCP::extract. 在提取过程中," IloCP::extract会放回 " IloConstraint的实例。

您必须使用以下 "IloCPConstraintI成员函数来强制提取变量或变量数组:

 void use(constIloCPEnginesolver, constIloNumVarx) const;
 void use(constIloCPEnginesolver, constIloIntervalVarx) const;
 void use(constIloCPEnginesolver, constIloIntervalSequenceVarx) const;

 void use(constIloCPEnginesolver, constIloNumVarArrayxa) const;
 void use(constIloCPEnginesolver, constIloIntervalVarArrayxa) const;
 void use(constIloCPEnginesolver, constIloIntervalSequenceVarArrayxa) const;
 

作为参数传递的每个对象类型都必须能被 "std::ostream类型的对象处理("display 成员函数需要该对象--见下文示例)。 如果需要,可以为约束包装器中使用的某个类型 "MyType编写类似下面的代码。 请注意,大多数 Concert 技术对象已经具备这种功能。

 std::ostream& operator << (std::ostream& out, constMyType& myObj) {
   // ... 插入显示myObj代码 ...
   返回;
 }
 

示例

下面介绍如何使用一个数据成员定义约束包装器:

 ILOCPCONSTRAINTWRAPPER1(IloFreqConstraint, cp,IloIntVarArray,_vars) {
   使用(cp, _vars);
   returnIlcFreqConstraint(cp, cp.getIntVarArray(_vars));
 }

要使用 "IloCPEngine::getIntVarArray,必须提取数组。 要强制提取可提取内容或可提取内容数组,请将它们作为 "use方法的参数传递。

宏生成的代码与下面几行类似:

 classIloFreqConstraintI: publicIloCPConstraintI{
 ilocpconstraintwrapperdecl
 private:
   IloIntVarArray_vars;

 public:
   IloFreqConstraintI(IloEnvI*,constIloIntVarArray&,const char*);
   virtualIloExtractableI* makeClone(IloEnvI*) const;
   virtual void display(ostream & out) const;
   IlcConstraintextract(constIloCPEngine) const;
 };

 ILOCPCONSTRAINTWRAPPERIMPLIloFreqConstraintI)

 IloFreqConstraintI::IloFreqConstraintI(IloEnvI*env、
                                     constIloIntVarArray&T_vars、
                                     const char* name) :
   IloCPConstraintI(env, name), _vars (IloIntVarArray&T_vars) {}

 IloExtractableI* IloFreqConstraintI::makeClone(IloEnvI*env) const {
   IloIntVarArray targ1=IloGetClone(env,_vars);
   return new (env)IloFreqConstraintI(env,
                                    (constIloIntVarArray &)targ1、
                                    (const char*)0);
 }

 voidIloFreqConstraintI::display(ostream&out) const {
   out <<"IloFreqConstraintI"<< " (";
   ifgetName()) out <<getName();
   else out <<getId(); out << ")" << std::endl;
   out << " " << "_vars" << " " << _vars <<
 std::endl;
 }

 IloConstraint IloFreqConstraint(IloEnv环境、
                               IloIntVarArray_vars、
                               const char*name=0){
   IloFreqConstraintI::InitTypeIndex();
   return new (env)IloFreqConstraintI(env.getImpl(), _vars, name);
 }

 IlcConstraint IloFreqConstraintI::extract(const IloCPEngine&cp) const
 {
   使用(cp, _vars);
   returnIlcFreqConstraint(cp, cp.getIntVarArray(_vars));
 }
 

另请参阅: