42 throw IPOE(
"PhaseIModel::getInitial_s(): vector size error." );
49 double const upperBound { constraint.getUpperBound() };
50 double const lowerBound { constraint.getLowerBound() };
53 auto subvector = constraintIndices_j->get( vector );
54 double const functionValue { (*constraint.getFunction())( subvector )};
57 double const lowerBound { constraint.getLowerBound() };
65 auto& variable = entry.first;
66 size_t index = entry.second;
67 double const upperBound { variable.getUpperBound() };
70 double const lowerBound { variable.getLowerBound() };
76 if( s < 1000 ) s += 0.1;
98 auto& modelVariable = entry.first;
99 size_t const INDEX { entry.second };
103 variable.setValue( modelVariable.getValue() );
105 indexMap.insert( std::make_pair( variable, INDEX ) );
106 crossIndex.insert( std::make_pair( modelVariable, variable ) );
110 size_t const INDEX =
indexMap.size();
111 indexMap.insert( std::make_pair( s, INDEX ) );
116 PhaseIObjectiveFunctionAndDerivatives( objectiveFunction ),
117 "Phase I objective" );
121 for(
auto& var : modelObjVars ) vars.push_back(
crossIndex.find( var )->second );
129 double const upperBound = constraint.getUpperBound();
132 std::string
name { constraint.getName() };
133 name +=
" (upper bound)";
137 auto& cVars = constraint.getVariables();
139 for(
auto& var : cVars ) vars.push_back(
crossIndex.find( var )->second );
142 c.getVariables() = vars;
144 c.setUpperBound( 0.0 );
148 double const lowerBound { constraint.getLowerBound() };
151 std::string
name { constraint.getName() };
152 name +=
" (lower bound)";
156 auto cVars = constraint.getVariables();
158 for(
auto& var : cVars ) vars.push_back(
crossIndex.find( var )->second );
162 c.getVariables() = vars;
164 c.setUpperBound( 0.0 );
176 Array vars( *
this, cVars.getName() );
181 linearConstraint.getVariables() = vars;
183 linearConstraint.setCoefficient( s, 0 );
184 for(
auto& variable : cVars )
185 linearConstraint.setCoefficient(
crossIndex.find( variable )->second,
186 equalityConstraint.getCoefficient( variable ) );
188 linearConstraint.setValue( equalityConstraint.getUpperBound() );
195 auto const& modelVar = entry.first;
196 double const upperBound = modelVar.getUpperBound();
199 std::string
name { modelVar.getName() };
200 name +=
" (variable upper bound)";
206 vars.push_back(
crossIndex.find( modelVar )->second );
210 c.getVariables() = vars;
212 c.setUpperBound( 0.0 );
216 double const lowerBound = modelVar.getLowerBound();
219 std::string
name { modelVar.getName() };
220 name +=
" (variable lower bound)";
226 vars.push_back(
crossIndex.find( modelVar )->second );
230 c.getVariables() = vars;
232 c.setUpperBound( 0.0 );
264 size_t const SIZE {
indexMap.size() };
265 gsl::vector vector( SIZE );
267 auto& variable = entry.first;
268 auto index = entry.second;
269 vector[index] = variable.getValue();
272 auto subvector = vector.subvector( 0, SIZE - 1 );
279 if( vector[SIZE - 1] < 0 or
minimise() ){
282 auto& variable = entry.first;
285 .setValue(
crossIndex.find( variable )->second.getValue() );
295 double constexpr ROOTEPS { std::sqrt( std::numeric_limits<double>::epsilon() ) };
297 if( ROWS == 0 )
return true;
300 if( COLS == 0 )
return true;
303 gsl::matrix A { std::max( ROWS, COLS ), COLS };
304 gsl::matrix V { COLS, COLS };
306 gsl::vector x( COLS );
307 gsl::vector S( COLS );
308 gsl::vector b( std::max( ROWS, COLS ) );
311 for(
size_t i { 0 }; i < ROWS; ++i ){
313 auto vars = equalityConstraint.getVariables();
315 for(
auto& var : vars ){
316 size_t const index {
indexMap[var] };
318 A.set( i,
indexMap[var], equalityConstraint.getCoefficient( var ) );
321 b[i] = equalityConstraint.getUpperBound();
323 auto handler = gsl::exception::set_handler_gsl_exceptions();
326 gsl::linalg::SV_decomp( A, V, S, x );
327 for(
auto& entry : S )
328 if( std::fabs( entry ) < ROOTEPS ) entry = 0;
329 gsl::linalg::SV_solve( A, V, S, b, x );
330 }
catch( gsl::exception e ){
333 gsl::exception::set_handler( handler );
334 throw IPOE(
"ipo::detail::PhaseIModel::findEqualityConstraintFeasibleSolution(): "
335 "unknown exception encountered." );
337 gsl::exception::set_handler( handler );
346 throw IPOE(
"ipo::detail::PhaseIModel::findEqualityConstraintFeasibleSolution(): "
347 "variable in phase I model fails to match variable in model." );
353 throw IPOE(
"ipo::detail::PhaseIModel::findEqualityConstraintFeasibleSolution(): "
354 "variable in phase I model not contained in its index map." );
355 size_t const index { r->second };
357 double const d { x[index] };
std::map< Variable, size_t > indexMap
Used internally to match the variables in each variable to indices in a vector.
void setValue(double const value)
Set value of variable.
virtual void setIndices()
Sets the values of objectiveIndices, constraintIndices and variableIndices from constraints.
std::vector< ipo::LinearConstraint > equalityConstraints
The set of equality constraints.
void push_back(value_type const &value)
Insert value at end of array.
bool minimise()
Try to minimise the objective function subject to the constraints.
detail::LineSearch::Parameters lineSearchParameters
Parameters used by backtracking line search algorithm during optimisation.
double constexpr infinity
Infinity: use for unbounded variables.
Namespace for details of ipo_function that are not normally needed to construct and solve a convex op...
bool variablesChanged
Value that indicates if any variables, objective or constraints have been modified in such a way that...
bool findFeasibleSolution()
Find a feasible solution to the base Model by partial optimisation of the PhaseIModel and copy the re...
detail::NewtonDescent::Parameters newtonDescentParameters
Parameters used by Newton descent algorithm during optimisation.
detail::NewtonDescent::Parameters & getNewtonDescentParameters()
Get Newton descent parameters by reference.
Array & getVariables()
Get variables used by Objective function.
Objective objective
The objective function.
Model & model
The Model this is based on.
std::map< Variable, Variable > crossIndex
A map so we can look up Variable of this from Variable of model.
Function for Phase I (feasibility) of interior-point optimisation.
Class to represent a linear combination as an Objective or Constraint.
#define IPOE(message)
Macro to allow file and line names in exceptions.
bool isStrictlyFeasible()
Test whether current values of variables give a feasible solution.
void setVariablesFromVector(gsl::vector const &vector)
Set variable values from a vector.
std::string getName() const
Get name of variable.
std::vector< Constraint > constraints
The set of constraints.
Class for a constraint function.
Model an interior-point optimisation problem.
Class for an objective function.
Namespace for classes that handle details of interior-point optimisation that are not ordinarily acce...
Function for Phase I (feasibility) of interior-point optimisation.
virtual void setIndices()
Sets the values of objectiveIndices, constraintIndices and variableIndices from Model.
This class computes a function at a vector.
PhaseIModel(Model &model)
Constructor.
void setObjectiveIndices()
Set objectiveIndices.
This class represents a variable.
std::string getName() const
Get name of variable.
virtual ::ipo_function::Function * getFunction()
Get function.
bool findEqualityConstraintFeasibleSolution()
Find a solution that satisfies equality constraints.
This class represents an array of Variable objects.
void setConstraintIndices()
Set constraintIndices.
double constexpr minusInfinity
Negative infinity: use for unbounded variables.
Parameters parameters
Parameters for interior point optimisation.
double getInitial_s(gsl::vector const &vector) const
Get an initial value for s from a vector of length one less than the number of variables of this mode...
std::vector< std::shared_ptr< Subvector > > constraintIndices
Used internally to match the variables in each constraint to indices in a vector: (*constraintIndices...
void setPhaseI(bool const phaseI)
This function is designed to be used to help find an initial (phase I) feasible solution.