Library
Module
FlexibilityAnalysis.FlexibilityAnalysis — Module.FlexibilityAnalysisA Julia package that implements a computational framework for quantifying and analyzing system flexibility.
The basic functionality emulates typical JuMP models to facilitate general computation of the flexibility index problem. Thus, basic functionality uses FlexibilityModel, @randomvariable, @recoursevariable, @variable, @constraint, setuncertaintyset, and solve.
Methods/Macros
Functions/Methods
FlexibilityAnalysis.FlexibilityModel — Function.FlexibilityModel(; [solver = JuMP.UnsetSolver()])Return a flexibility model object which extends a JuMP model object to contain FlexibilityData and implement a custom solvehook. An appropriate solver should be specified in order solve the flexibility index problem. A solver capable of handling MIQCPs is required for ellipsoidal and 2-norm uncertainty sets otherwise a MILP solver can be used. This model is solved with solve, see solvehook for documention on the accepted keyword arguments.
Arguments
solver = JuMP.UnsetSolver()The solver, should use an MIQCP, MINLP, or MILP solver as appropriate.
julia> m = FlexibilityModel(solver = GurobiSolver())
Feasibility problem with:
* 0 linear constraints
* 0 variables
Solver is GurobiFlexibilityAnalysis.@randomvariable — Macro.@randomvariable(m, x, mean)Defines a random variable using RandomVariable(m::Model, mean::Number, name::AbstractString) and requires that a mean for the variable be provided. This can later be overwritten with setmean.
Arguments
m::ModelThe flexibility model.x::SymbolThe variable name.mean::NumberThe variable mean
julia> @randomvariable(m2, w, mean = 42)
julia> @randomvariable(m2, ws[i = 1:4], mean = 42)
4-element Array{FlexibilityAnalysis.RandomVariable,1}:
FlexibilityAnalysis.RandomVariable(Feasibility problem with:
* 9 linear constraints
* 89 variables
julia> @randomvariable(m2, ws[i = 1:4], mean = [1; 2; 3; 4][i])
4-element Array{FlexibilityAnalysis.RandomVariable,1}:
FlexibilityAnalysis.RandomVariable(Feasibility problem with:
* 9 linear constraints
* 96 variables@recoursevariable(m, x)Defines a recourse variable using RecourseVariable(m::Model, name::AbstractString).
Arguments
m::ModelThe flexibility model.x::SymbolThe variable name.
julia> @recoursevariable(m2, d)
julia> @recoursevariable(m2, ds[1:4])
4-element Array{FlexibilityAnalysis.RecourseVariable,1}:
FlexibilityAnalysis.RecourseVariable(Feasibility problem with:
* 9 linear constraints
* 101 variablesFlexibilityAnalysis.getflexibilitydata — Function.getflexibilitydata(m::Model)Return the FlexibilityData corresponding the flexibility model m. An error is thrown if m is a regular JuMP model.
Arguments
m::ModelThe flexibility model.
julia> getflexibilitydata(m)
FlexibilityAnalysis.FlexibilityData(JuMP.AbstractConstraint[], 0, Number[], AbstractString[], Int64[], 0, AbstractString[], Int64[], FlexibilityAnalysis.EllipsoidalSet(:Ellipsoid, false), Array{Number}(undef,0,0), nothing, Int64[], nothing)FlexibilityAnalysis.setcovariance — Function.setcovariance(m::Model, covariance::Matrix)Specify the covariance matrix covariance to be stored in the flexibility model m. This method verifies that the matrix is symmetric positive semi-definite and writes it to FlexibilityData.covariance.
Arguments
m::ModelThe flexibility model.covariance::MatrixThe covariance matrix.
julia> setcovariance(m, [2 1; 1 2])
2×2 Array{Int64,2}:
2 1
1 2FlexibilityAnalysis.getcovariance — Function.getcovariance(m::Model)Return the current covariance matrix in the flexibility model as stored in FlexibilityData.covariance.
Arguments
m::ModelThe flexibility model.
julia> getcovariance(m)
4×4 Array{Number,2}:
11.11 0.0 0.0 0.0
0.0 11.11 0.0 0.0
0.0 0.0 11.11 0.0
0.0 0.0 0.0 11.11FlexibilityAnalysis.setmean — Function.setmean(m::Model, mean::Vector)Specify the mean corresponding to FlexibilityData.RVmeans stored in the flexibility model m. This method verifies that the length of the input mean matches the length of FlexibilityData.RVmeans before overwriting the current mean.
Arguments
m::ModelThe flexibility model.mean::VectorThe means of the random variables.
setmean(m, [2.3; 5])
2-element Array{Float64,1}:
2.3
5.0FlexibilityAnalysis.getmean — Method.getmean(m::Model)Return the current mean vector in the flexibility model as stored in FlexibilityData.RVmeans.
Arguments
m::ModelThe flexibility model.
julia> getmean(m)
4-element Array{Number,1}:
620
388
583
313FlexibilityAnalysis.getmean — Method.getmean(variable::RandomVariable)Return the mean corresponding to a particular RandomVariable. Currently this only accepts a single random variable and vector variables are not accepted directly.
Arguments
variable::RandomVariableThe random variable name, must be a single variable.
julia> getmean(T[1])
620FlexibilityAnalysis.setuncertaintyset — Function.setuncertaintyset(m::Model, uncertainty_set::Symbol, [attribute = nothing; only_positive::Bool = false])Specify the type of uncertainty set to be used and stored in FlexibilityData.uncertainty_set and provide the necessary attribute. An ellipsoidal uncertainty set can be specified with the :Ellipsoid symbol and the corresponding covariance matrix will need to input via attribute if it has not already been set with setcovariance. A hyperbox uncertainty set is specified with the :Hyperbox symbol and corresponding negative/positive deviation vectors need to be inputed via attribute as a vector of vectors of the form [[neg_dev]; [pos_dev]]. Finally, a p-norm uncertainty set can be specified with the :PNorm symbol and providing the corresponding p value via attribute where p can equal 1, 2, or Inf.
Arguments
m::ModelThe flexibility model.uncertainty_set::SymbolThe uncertainty set name.attribute = nothingThe necessary atribute for the specified uncertainty set.
Keyword Arguments
only_positive::Bool = falseIndicate if the uncertainty set should be intersected with the set of all positive values.
julia> setuncertaintyset(m, :Ellipsoid)
julia> setuncertaintyset(m, :Ellipsoid, eye(4)* 11.11)
julia> setuncertaintyset(m, :Hyperbox, [[ones(4)]; [ones(4)]])
FlexibilityAnalysis.HyperboxSet(:Hyperbox, Number[1.0, 1.0, 1.0, 1.0], Number[1.0, 1.0, 1.0, 1.0], false)
julia> setuncertaintyset(m, :PNorm, 1)
FlexibilityAnalysis.PNormSet(:PNorm, 1, false)
julia> setuncertaintyset(m, :PNorm, 2, only_positive = true)
FlexibilityAnalysis.PNormSet(:PNorm, 2, true)
julia> setuncertaintyset(m, :PNorm, Inf)
FlexibilityAnalysis.PNormSet(:PNorm, Inf, false)FlexibilityAnalysis.ismeanfeasible — Function.ismeanfeasible(m::Model; [toler::Number = 1e-5, solver = Clp.ClpSolver()])Returns a Bool indicating if the mean stored in FlexibilityData.RVmeans is feasible, meaning that it lies inside the feasible region. This check is done using the so-called feasibility function.
Arguments
m::ModelThe flexibility model.
Keyword Arguments
toler::Number = 1e-5The numerical tolerance for checking the feasibility.solver = Clp.ClpSolver()The solver, any LP or NLP solver shoudl work.
julia> ismeanfeasible(m)
true
julia> ismeanfeasible(m, solver = GurobiSolver(OutputFlag = 0))
Academic license - for non-commercial use only
trueFlexibilityAnalysis.findcenteredmean — Function.findcenteredmean(m::Model; [center::Symbol = :feasible, solver = Ipopt.IpoptSolver(print_level = 0), toler::Number = 1e-5, update_mean::Bool = false, only_positive::Bool = false])Returns a center point based on the analytic or feasible center. The result can overwrite the mean stored in FlexibilityData.RVmeans if desired. This is a wrapper function for ComputeCenter.
Arguments
m::ModelThe flexibility model.
Keyword Arguments
center::Symbol = :feasibleIndicates the type of center, accepted arguments are:feasibleand:analytic.solver = Ipopt.IpoptSolver(print_level = 0)The solver which must be an NLP solver for the analytic center.toler::Number = 1e-5The tolerance to check solution validity.update_mean::Bool = falseIndicates if the computed center should overwriteFlexibilityData.RVmeans.only_positive::Bool = falseIndicates if the center need by strictly positive.
julia> findcenteredmean(m, only_positive = true)
4-element Array{Float64,1}:
1684.74
79.0718
195.073
0.0
julia> findcenteredmean(m, center = :analytic, update_mean = true)
4-element Array{Float64,1}:
898.125
-507.214
594.544
317.23FlexibilityAnalysis.getflexibilityindex — Function.getflexibilityindex(m::Model)Return the current flexibility index in the flexibility model as stored in FlexibilityData.flexibility_index.
Arguments
m::ModelThe flexibility model.
julia> getflexibilityindex(m)
3.5993764186390327FlexibilityAnalysis.getconfidencelevel — Function.getconfidencelevel(m::Model)Return the confidence level provided that the flexibility model m has been solved with an ellipsoidal uncertainty set. This is equivalent to the quantile associated with the optimized uncertainty set. Note that this assumes a multivariate Gaussian distribution with mean FlexibilityData.RVmeans and covariance FlexibilityData.covariance.
Arguments
m::ModelThe flexibility model.
julia> getconfidencelevel(m)
0.5370703369769008FlexibilityAnalysis.getsolutiontime — Function.getsolutiontime(m::Model)Return the solution time to compute the flexibility index as stored in the flexibility model as stored in FlexibilityData.solution_time.
Arguments
m::ModelThe flexibility model.
julia> getsolutiontime(m)
0.00199127197265625FlexibilityAnalysis.getactiveconstraints — Function.getactiveconstraints(m::Model)Return the current vector of active constraint indexes in the flexibility model as stored in FlexibilityData.active_constraints.
Arguments
m::ModelThe flexibility model.
julia> getactiveconstraints(m)
2-element Array{Int64,1}:
3
6JuMP.getvalue — Method.JuMP.getvalue(v::FlexibilityVariable)Return the value of the a flexibility variable this is an extension of JuMP.getvalue.
Arguments
v::FlexibilityVariableThe flexibility variable.
julia> getvalue(T)
4-element Array{Float64,1}:
620.0
388.0
581.0
319.0FlexibilityAnalysis.rankinequalities — Function.rankinequalities(m::Model; max_ranks::Int = 5, suppress_warnings::Bool = true, U::Int = 10000, diag::Bool = false, active_constr::Bool = false, real_recourse_dim::Int = -1, conic_δ::Bool = false)Returns ranking data in the form Vector{Dict} where each dictionary corresponds to a particular rank level and contains the optimal flexibility_index, active constraint indexes, and flexibility model. The function will iteratively solve copies of the flexibility model via solve where the prior active constraints are turned off in order rank the most limiting constraints. The user can specify the maximum number of rank levels and the flexibility index problem will be repeatedly solved until that maximum is acheived or the problem becomes unbounded, which occurs first.
Arguments
m::ModelThe flexibility model.
Keyword Arguments
max_ranks::Int = 5The maximum number of rank levels. 2suppress_warnings::Bool = falseIndicates if solver warnings should be suppressed.U::Union{Int, Float64} = 10000The slack variable upper bound.diag::Bool = falseIndicates whether or not to diagnonalize ellipsoidal uncertainty set (this is only active when an ellipsoidal set is used).active_constr::Bool = falseIndicates if the optional active constraint should be used which enforces how many inequalities are active at the solution, this must be set totruefor systems without control variables and/or contain state variables.real_recourse_dim::Int = -1The actual number of recourse variables in case state variables are included as recourse variables. This is mandatory ifactive_constr = trueand no state variables are provided.conic_δ::Bool = falseThis should be set totrueif a conic solver is used such as Pajarito.jl.
julia> rankinequalities(m, active_constr = true)
2-element Array{Dict,1}:
Dict{String,Any}(Pair{String,Any}("flexibility_index", 3.59938),Pair{String,Any}("model", Feasibility problem with:
* 6 linear constraints
* 6 variables
Solver is Pavito),Pair{String,Any}("active_constraints", [3, 6]))
Dict{String,Any}(Pair{String,Any}("flexibility_index", 9.58983),Pair{String,Any}("model", Feasibility problem with:
* 6 linear constraints
* 6 variables
Solver is Pavito),Pair{String,Any}("active_constraints", [1, 5]))FlexibilityAnalysis.findstochasticflexibility — Function.findstochasticflexibility(m::Model; num_pts::Int = 10000, toler::Number = 1e-5, solver = Clp.ClpSolver(), only_positive::Bool = false, use_vulnerability_model::Bool = false, use_flexibility_index::Bool = false, seed::Int = -1)Returns the estimated stochastic flexibility index that is evaluated via Monte Carlo sampling. At default this estimation is carried out by evaluating the feasibility of each Monte Carlo sample. The samples are generating from a multivariate Gaussian distribution with mean FlexibilityData.RVmeans and covariance FlexibilityData.covariance. The vulnerability model also tests the feasibility of the samples, but does so in one large optimization problem instead of evaluating each sample indiviually. The optimized flexibility index can also be used to reduce the number of samples that need to be evaluated.
Arguments
m::ModelThe flexibility model.
Keyword Arguments
num_pts::Int = 10000Number of Monte Carlo samples.toler::Number = 1e-5The feasibility check tolerance.solver = Clp.ClpSolver()The solver, any LP or NLP solver should work.only_positive::Bool = falseIndicates if only positive samples should be used.use_vulnerability_model::Bool = falseIndicates if the vulnerability model should be used.use_flexibility_index::Bool = falseIndicates if the optimal flexibility index should be used.seed::Int = -1Random seed for sample collection, any negative value will turn off the random seed.
julia> findstochasticflexibility(m)
0.9687
julia> findstochasticflexibility(m, use_vulnerability_model = true)
0.9705
julia> findstochasticflexibility(m, num_pts = 5000, use_flexibility_index = true)
0.973JuMP.linearindex — Method.JuMP.linearindex(v::FlexibilityVariable)Return the index of the a flexibility variable this is an extension of JuMP.linearindex.
Arguments
v::FlexibilityVariableThe flexibility variable, must be a single variable.
julia> linearindex(Qc)
1DataTypes
FlexibilityVariable <: JuMP.AbstractJuMPScalarAn abstract type to define new variable types.
RandomVariable <: FlexibilityVariableA DataType for random variables.
Fields
m::ModelFlexibility model.idx::IntIndex of variable in model.
RecourseVariable <: FlexibilityVariableA DataType for recourse variables.
Fields
m::ModelFlexibility model.idx::IntIndex of variable in model.
FlexibilityExpr <: JuMP.GenericAffExprA GenericAffExpr that contains random and/or recourse variables.
FlexibilityConstraint <: JuMP.AbstractConstraintA constraint that contains random and/or recourse variables.
Fields
flex_expr::FlexibilityExprConstraint expression.sense::SymbolThe cosntraint sense symbol:(<=)or:(>=)or:(==).
AbstractUncertaintySetAn abstract type to define new uncertainty set types.
EllipsoidalSet <: AbstractUncertaintySetAn ellipsoidal uncertainty set that will use the covariance matrix stored in FlexibilityData.
Fields
name::SymbolName of the set which will be:Ellipsoid.only_positive::BoolAn option to indicate if the set should be intersected with the set all positive numbers.
FlexibilityAnalysis.HyperboxSet — Type.HyperboxSet <: AbstractUncertaintySetA hyperbox uncertainty set whose nomimal dimensions are determined by neg_dev and pos_dev.
Fields
name::SymbolName of the set which will be:Hyperbox.neg_dev::Vector{Number}A vector of the expected negative deviation of the random variables.pos_dev::Vector{Number}A vector of the expected positive deviation of the random variables.only_positive::BoolAn option to indicate if the set should be intersected with the set all positive numbers.
FlexibilityAnalysis.PNormSet — Type.PNormSet <: AbstractUncertaintySetA p-norm based uncertainty set based on a bounded p-norm.
Fields
name::SymbolName of the set which will be:PNorm.p::NumberThe value of p which can be 1, 2, or Inf.only_positive::BoolAn option to indicate if the set should be intersected with the set all positive numbers.
FlexibilityDataA DataType for storing the data necessary to manage the bookkeeping of the flexibility variables (RandomVariable and RecourseVariable), the uncertainty set, and solution results.
Fields
flexibility_constraints::Vector{JuMP.AbstractConstraint}Constraints that involve flexibility variables.numRVs::IntThe number ofRandomVariablethat have been added to the model.RVmeans::Vector{Number}The means corresponding to eachRandomVariable.RVnames::Vector{AbstractString}The symbolic name of eachRandomVariable.RVcols::Vector{Int}The index of eachRandomVariable.num_recourse_vars::IntThe number ofRecourseVariablethat have been added to the model.recourse_names::Vector{AbstractString}The symbolic name of eachRecourseVariable.recourse_cols::Vector{Int}The index of eachRecourseVariable.uncertainty_set::AbstractUncertaintySetThe uncertainty set DataType with all of the set specfic attributes.covariance::Matrix{Number}The covariance matrix.flexibility_index::Union{Nothing, Number}The flexibility index result obtained from solving the flexibility model.active_constraints::Vector{Int}The indexes of the active inequality constraints at the solution of the flexibility model.- 'solution_time::Number' The solution time in seconds.
Internals
FlexibilityAnalysis.getuncertaintyset — Function.getuncertaintyset(m::Model)Return the current uncertainty set datatype in the flexibility modelas stored in FlexibilityData.uncertaintyset.
Arguments
m::ModelThe flexibility model.
FlexibilityAnalysis.solvehook — Function.solvehook(m::Model; [suppress_warnings::Bool = false, U::Number = 10000, diag::Bool = false, active_constr::Bool = false, real_recourse_dim::Int = -1, conic_δ::Bool = false, inactives::Vector = []])Returns the solution status to solving the flexibility model m. This solvehook what JuMP.solve(::Model) for flexibility models. This solves the flexibility index problem using the variables and constraints specified in m.
Arguments
m::ModelThe flexibility model.
Keyword Arguments
suppress_warnings::Bool = falseIndicates if solver warnings should be suppressed.U::Number = 10000The slack variable upper bound.diag::Bool = falseIndicates if the ellipsoidal uncertainty set is diagonalized (this is only active when an ellipsoidal set is used).active_constr::Bool = falseIndicates if the optional active constraint should be used which enforces how many inequalities are active at the solution, this must be set totruefor systems without control variables and/or contain state variables.real_recourse_dim::Int = -1The actual number of recourse variables in case state variables are included as recourse variables. This is mandatory ifactive_constr = trueand no state variables are provided.conic_δ::Bool = falseThis should be set totrueif a conic solver is used such as Pajarito.jl.inactives::Vector = []The indexes of inequality constraints that should be turned off.
FlexibilityAnalysis.MakeInputDict — Function.MakeInputDict(m::Model)Returns input_dict::Dict which contains the state space representation of the system equations stored in the flexibility model. The resulting input_dict is used by most of the flexibility analysis functions.
Arguments
m::ModelThe flexibility model.
FlexibilityAnalysis.AddSystemExpressions — Function.AddSystemExpressions(m::Model, input_dict::Dict, [num_scenarios::Int = 0])Returns a vector of vectors where the first contains all the inequality expressions corresponding to the inequalities defined in input_dict and the second contains all of the equality expressions corresponding to the equalities defined in input_dict.
Arguments
m::ModelThe flexibility model.input_dict::DictInput dictionary as defined byMakeInputDict.num_scenarios::Int = 0The number of scenerio subproblems, 0 turns off this feature.
FlexibilityAnalysis.RandomVariable — Method.RandomVariable(m::Model, mean::Number, name::AbstractString)Return a RandomVariable DataType for given flexibility model m given the mean and the name. An anonymous JuMP variable is added directly to the flexibility model and its is appended to FlexibilityData.RVcols.
Arguments
m::ModelThe flexibility model.mean::NumberThe variable mean.name::AbstractStringThe variable name.
FlexibilityAnalysis.RecourseVariable — Method.RecourseVariable(m::Model, name::AbstractString)Return a RecourseVariable DataType for given flexibility model m given the name. An anonymous JuMP variable is added directly to the flexibility model and its is appended to FlexibilityData.recourse_cols.
Arguments
m::ModelThe flexibility model.name::AbstractStringThe variable name.
Base.show — Method.Base.show(io::IO, a::FlexibilityExpr)Extend Base.show to print flexibility expressions.
JuMP.addconstraint — Method.JuMP.addconstraint(m::Model, constr::FlexibilityConstraint)Extend the JuMP.addconstraint function to handle FlexibilityConstraint types.
Base.show — Method.JuMP.show(io::IO,c::FlexibilityConstraint)Extend the JuMP.show function to handle FlexibilityConstraint types.
JuMP.constructconstraint! — Method.JuMP.constructconstraint!(flex_aff::FlexibilityExpr, sense::Symbol)Extends JuMP.constructconstraint! for FlexibilityExpr types.
FlexibilityAnalysis.ComputeCenter — Function.ComputeCenter(m::Model, center::Symbol, solver, toler::Number, only_positive::Bool)Returns a center point that can be used to replace the mean if desired.
Arguments
m::ModelThe flexibility model.center::SymbolIndicates the type of center, accepted arguments are:feasibleand:analytic.solverThe solver which must be an NLP solver for the analytic center.toler::NumberThe tolerance to check solution validity.only_positive::BoolIndicates if the center need by strictly positive.
Index
Base.showBase.showFlexibilityAnalysis.AddSystemExpressionsFlexibilityAnalysis.ComputeCenterFlexibilityAnalysis.FlexibilityModelFlexibilityAnalysis.MakeInputDictFlexibilityAnalysis.findcenteredmeanFlexibilityAnalysis.findstochasticflexibilityFlexibilityAnalysis.getactiveconstraintsFlexibilityAnalysis.getconfidencelevelFlexibilityAnalysis.getcovarianceFlexibilityAnalysis.getflexibilitydataFlexibilityAnalysis.getflexibilityindexFlexibilityAnalysis.getmeanFlexibilityAnalysis.getmeanFlexibilityAnalysis.getsolutiontimeFlexibilityAnalysis.getuncertaintysetFlexibilityAnalysis.ismeanfeasibleFlexibilityAnalysis.rankinequalitiesFlexibilityAnalysis.setcovarianceFlexibilityAnalysis.setmeanFlexibilityAnalysis.setuncertaintysetFlexibilityAnalysis.solvehookJuMP.addconstraintJuMP.constructconstraint!JuMP.getvalueJuMP.linearindexFlexibilityAnalysis.AbstractUncertaintySetFlexibilityAnalysis.EllipsoidalSetFlexibilityAnalysis.FlexibilityConstraintFlexibilityAnalysis.FlexibilityDataFlexibilityAnalysis.FlexibilityExprFlexibilityAnalysis.FlexibilityVariableFlexibilityAnalysis.HyperboxSetFlexibilityAnalysis.PNormSetFlexibilityAnalysis.RandomVariableFlexibilityAnalysis.RandomVariableFlexibilityAnalysis.RecourseVariableFlexibilityAnalysis.RecourseVariable