ScSolverCellHashMap aCellsHash;
aCellsHash[maObjective].reserve( nVariables + 1 ); // objective function
for (constauto& rConstr : maConstraints)
{
table::CellAddress aCellAddr = rConstr.Left;
aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: left hand side
if ( rConstr.Right >>= aCellAddr )
aCellsHash[aCellAddr].reserve( nVariables + 1 ); // constraints: right hand side
}
// set all variables to zero //! store old values? //! use old values as initial values? for ( constauto& rVarCell : aVariableCells )
{
SolverComponent::SetValue( mxDoc, rVarCell, 0.0 );
}
// read initial values from all dependent cells for ( auto& rEntry : aCellsHash )
{ double fValue = SolverComponent::GetValue( mxDoc, rEntry.first );
rEntry.second.push_back( fValue ); // store as first element, as-is
}
// loop through variables for ( constauto& rVarCell : aVariableCells )
{
SolverComponent::SetValue( mxDoc, rVarCell, 1.0 ); // set to 1 to examine influence
// read value change from all dependent cells for ( auto& rEntry : aCellsHash )
{ double fChanged = SolverComponent::GetValue( mxDoc, rEntry.first ); double fInitial = rEntry.second.front();
rEntry.second.push_back( fChanged - fInitial );
}
SolverComponent::SetValue( mxDoc, rVarCell, 2.0 ); // minimal test for linearity
for ( constauto& rEntry : aCellsHash )
{ double fInitial = rEntry.second.front(); double fCoeff = rEntry.second.back(); // last appended: coefficient for this variable double fTwo = SolverComponent::GetValue( mxDoc, rEntry.first );
bool bLinear = rtl::math::approxEqual( fTwo, fInitial + 2.0 * fCoeff ) ||
rtl::math::approxEqual( fInitial, fTwo - 2.0 * fCoeff ); // second comparison is needed in case fTwo is zero if ( !bLinear )
maStatus = SolverComponent::GetResourceString( RID_ERROR_NONLINEAR );
}
SolverComponent::SetValue( mxDoc, rVarCell, 0.0 ); // set back to zero for examining next variable
}
xModel->unlockControllers();
if ( !maStatus.isEmpty() ) return;
// // build parameter arrays for CoinMP //
// set objective function
const std::vector<double>& rObjCoeff = aCellsHash[maObjective];
std::unique_ptr<double[]> pObjectCoeffs(newdouble[nVariables]); for (nVar=0; nVar<nVariables; nVar++)
pObjectCoeffs[nVar] = rObjCoeff[nVar+1]; double nObjectConst = rObjCoeff[0]; // constant term of objective
// add rows
size_t nRows = maConstraints.getLength();
size_t nCompSize = nVariables * nRows;
std::unique_ptr<double[]> pCompMatrix(newdouble[nCompSize]); // first collect all coefficients, row-wise for (size_t i=0; i<nCompSize; i++)
pCompMatrix[i] = 0.0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.