本文整理汇总了C++中VariableList::GetInitialValues方法的典型用法代码示例。如果您正苦于以下问题:C++ VariableList::GetInitialValues方法的具体用法?C++ VariableList::GetInitialValues怎么用?C++ VariableList::GetInitialValues使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VariableList
的用法示例。
在下文中一共展示了VariableList::GetInitialValues方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateFunctionOptimizer
OptError NewtonProblem::CreateFunctionOptimizer(OptimizeClass *
&objfcn, NLP0 * &func)
{
OptError error;
int numVar = GetNumVar();
int derivOrder = GetDerivOrder();
VariableList* variables = GetVariables();
CompoundConstraint* constraints = 0;
if ((variables->linearExists()) || (variables->nonlinearExists()))
{
cout << "Newton does not support linear or nonlinear constraints." << endl;
cout << "Linear and nonlinear constraints being ignored." << endl;
}
if ((variables->upperExists()) || (variables->lowerExists()))
{
constraints = new CompoundConstraint(Constraint(variables->GetBoundConstraints()));
}
if(derivOrder == 2)
{
USERFCN2 userFcn = GetUserFunction2();
INITFCN initFcn = GetInitFunction();
if(userFcn == NULL || initFcn == NULL)
{
error.value = -4;
error.msg = "Error loading function";
return error;
}
NLF2 * myFunc = new NLF2(numVar, userFcn, initFcn, constraints);
myFunc->setIsExpensive(true);
myFunc->setX(variables->GetInitialValues());
if ((variables->upperExists()) || (variables->lowerExists()))
{
objfcn = new OptBCNewton(myFunc);
}
else
{
objfcn = new OptNewton(myFunc);
}
func = myFunc;
}
else if(derivOrder == 1)
{
// construct a function with 1st derivative info
USERFCN1 userFcn = GetUserFunction1();
INITFCN initFcn = GetInitFunction();
if(userFcn == NULL || initFcn == NULL)
{
error.value = -4;
error.msg = "Error loading function";
return error;
}
NLF1 * myFunc = new NLF1(numVar, userFcn, initFcn, constraints);
myFunc->setIsExpensive(true);
myFunc->setX(variables->GetInitialValues());
if ((variables->upperExists()) || (variables->lowerExists()))
{
objfcn = new OptBCQNewton(myFunc);
}
else
{
objfcn = new OptQNewton(myFunc);
}
func = myFunc;
}
else if(derivOrder == 0)
{
INITFCN initFcn = GetInitFunction();
USERFCN0 userFcn = GetUserFunction0();
if(userFcn == NULL)
{
error.value = -4;
error.msg = "Error loading user function";
return error;
}
else if(initFcn == NULL)
{
error.value = -4;
error.msg = "Error loading init function";
return error;
}
// construct a function with no derivative info
// but use finite differences to approximate a first derivative
FDNLF1 * myFunc = new FDNLF1(numVar, userFcn, initFcn, constraints);
myFunc->setIsExpensive(true);
myFunc->setX(variables->GetInitialValues());
if(searchType_ == trustPDS)
myFunc->setSpecOption(NoSpec);
//.........这里部分代码省略.........
示例2: CreateFunctionOptimizer
OptError CGProblem::CreateFunctionOptimizer(OptimizeClass* &objfcn,
NLP0* &func)
{
OptError error;
int numVar = GetNumVar();
int derivOrder = GetDerivOrder();
VariableList* variables = GetVariables();
if ((variables->upperExists()) || (variables->lowerExists()) ||
(variables->linearExists()) || (variables->nonlinearExists()))
{
cout << "CG does not support constraints." << endl;
cout << "Constraints being ignored." << endl;
}
// construct a function with 2nd derivative info
if(derivOrder == 2)
{
USERFCN2 userFcn = GetUserFunction2();
INITFCN initFcn = GetInitFunction();
if(userFcn == NULL || initFcn == NULL)
{
error.value = -4;
error.msg = "Error loading function";
return error;
}
NLF2* myFunc = new NLF2(numVar, userFcn, initFcn);
myFunc->setIsExpensive(true);
myFunc->setX(variables->GetInitialValues());
func = myFunc;
}
else if(derivOrder == 1)
{
// construct a function with 1st derivative info
USERFCN1 userFcn = GetUserFunction1();
INITFCN initFcn = GetInitFunction();
if(userFcn == NULL || initFcn == NULL)
{
error.value = -4;
error.msg = "Error loading function";
return error;
}
NLF1* myFunc = new NLF1(numVar, userFcn, initFcn);
myFunc->setIsExpensive(true);
myFunc->setX(variables->GetInitialValues());
func = myFunc;
}
else if(derivOrder == 0)
{
USERFCN0 userFcn = GetUserFunction0();
INITFCN initFcn = GetInitFunction();
if(userFcn == NULL || initFcn == NULL)
{
error.value = -4;
error.msg = "Error loading function";
return error;
}
// construct a function with no derivative info
// but use finite differences to approximate a first derivative
FDNLF1* myFunc = new FDNLF1(numVar, userFcn, initFcn);
myFunc->setIsExpensive(true);
myFunc->setX(variables->GetInitialValues());
func = myFunc;
}
objfcn = new OptCG((NLP1 *)func);
error.value = 0;
error.msg = "Success";
return error;
}