diff --git a/dev/.documenter-siteinfo.json b/dev/.documenter-siteinfo.json index 2f50c75..1e298c4 100644 --- a/dev/.documenter-siteinfo.json +++ b/dev/.documenter-siteinfo.json @@ -1 +1 @@ -{"documenter":{"julia_version":"1.10.0","generation_timestamp":"2024-02-08T20:45:17","documenter_version":"1.2.1"}} \ No newline at end of file +{"documenter":{"julia_version":"1.10.3","generation_timestamp":"2024-05-20T12:55:56","documenter_version":"1.4.1"}} \ No newline at end of file diff --git a/dev/api/index.html b/dev/api/index.html index 8c7ed7b..d419b08 100644 --- a/dev/api/index.html +++ b/dev/api/index.html @@ -1,85 +1,85 @@ -API · DisjunctiveProgramming.jl

API

DisjunctiveProgramming.@disjunctionMacro
@disjunction(model, expr, kw_args...)

Add a disjunction described by the expression expr, which must be a Vector of LogicalVariableRefs.

@disjunction(model, ref[i=..., j=..., ...], expr, kw_args...)

Add a group of disjunction described by the expression expr parameterized by i, j, ..., which must be a Vector of LogicalVariableRefs.

In both of the above calls, a Disjunct tag can be added to create nested disjunctions.

The recognized keyword arguments in kw_args are the following:

  • base_name: Sets the name prefix used to generate constraint names. It corresponds to the constraint name for scalar constraints, otherwise, the constraint names are set to base_name[...] for each index ... of the axes axes.
  • container: Specify the container type.
  • exactly1: Specify a Bool whether a constraint should be added to only allow selecting one disjunct in the disjunction.

To create disjunctions without macros, see disjunction.

source
DisjunctiveProgramming.@disjunctionsMacro
@disjunctions(model, args...)

Adds groups of disjunctions at once, in the same fashion as the @disjunction macro.

The model must be the first argument, and multiple disjunctions can be added on multiple lines wrapped in a begin ... end block.

The macro returns a tuple containing the disjunctions that were defined.

Example

julia model = GDPModel(); @variable(model, w); @variable(model, x); @variable(model, Y[1:4], LogicalVariable); @constraint(model, [i=1:2], w == i, Disjunct(Y[i])); @constraint(model, [i=3:4], x == i, Disjunct(Y[i])); @disjunctions(model, begin [Y[1], Y[2]] [Y[3], Y[4]] end);`

source
DisjunctiveProgramming.binary_variableMethod
binary_variable(vref::LogicalVariableRef)::JuMP.AbstractVariableRef

Returns the underlying binary variable for the logical variable vref which is used in the reformulated model. This is helpful to embed logical variables in algebraic constraints.

source
DisjunctiveProgramming.disjunctionFunction
disjunction(
+API · DisjunctiveProgramming.jl

API

DisjunctiveProgramming.@disjunctionMacro
@disjunction(model, expr, kw_args...)

Add a disjunction described by the expression expr, which must be a Vector of LogicalVariableRefs.

@disjunction(model, ref[i=..., j=..., ...], expr, kw_args...)

Add a group of disjunction described by the expression expr parameterized by i, j, ..., which must be a Vector of LogicalVariableRefs.

In both of the above calls, a Disjunct tag can be added to create nested disjunctions.

The recognized keyword arguments in kw_args are the following:

  • base_name: Sets the name prefix used to generate constraint names. It corresponds to the constraint name for scalar constraints, otherwise, the constraint names are set to base_name[...] for each index ... of the axes axes.
  • container: Specify the container type.
  • exactly1: Specify a Bool whether a constraint should be added to only allow selecting one disjunct in the disjunction.

To create disjunctions without macros, see disjunction.

source
DisjunctiveProgramming.@disjunctionsMacro
@disjunctions(model, args...)

Adds groups of disjunctions at once, in the same fashion as the @disjunction macro.

The model must be the first argument, and multiple disjunctions can be added on multiple lines wrapped in a begin ... end block.

The macro returns a tuple containing the disjunctions that were defined.

Example

julia model = GDPModel(); @variable(model, w); @variable(model, x); @variable(model, Y[1:4], LogicalVariable); @constraint(model, [i=1:2], w == i, Disjunct(Y[i])); @constraint(model, [i=3:4], x == i, Disjunct(Y[i])); @disjunctions(model, begin [Y[1], Y[2]] [Y[3], Y[4]] end);`

source
DisjunctiveProgramming.binary_variableMethod
binary_variable(vref::LogicalVariableRef)::JuMP.AbstractVariableRef

Returns the underlying binary variable for the logical variable vref which is used in the reformulated model. This is helpful to embed logical variables in algebraic constraints.

source
DisjunctiveProgramming.disjunctionFunction
disjunction(
     model::JuMP.AbstractModel,
     disjunct_indicators::Vector{LogicalVariableRef},
     [nested_tag::Disjunct],
     [name::String = ""];
     [exactly1::Bool = true]
-)

Create a disjunction comprised of disjuncts with indicator variables disjunct_indicators and add it to model. For nested disjunctions, the nested_tag is required to indicate which disjunct it will be part of in the parent disjunction. By default, exactly1 adds a constraint of the form @constraint(model, disjunct_indicators in Exactly(1)) only allowing one of the disjuncts to be selected; this is required for certain reformulations like Hull. For nested disjunctions, exactly1 creates a constraint of the form @constraint(model, disjunct_indicators in Exactly(nested_tag.indicator)). To conveniently generate many disjunctions at once, see @disjunction and @disjunctions.

source
DisjunctiveProgramming.make_disaggregated_variableMethod
make_disaggregated_variable(
+)

Create a disjunction comprised of disjuncts with indicator variables disjunct_indicators and add it to model. For nested disjunctions, the nested_tag is required to indicate which disjunct it will be part of in the parent disjunction. By default, exactly1 adds a constraint of the form @constraint(model, disjunct_indicators in Exactly(1)) only allowing one of the disjuncts to be selected; this is required for certain reformulations like Hull. For nested disjunctions, exactly1 creates a constraint of the form @constraint(model, disjunct_indicators in Exactly(nested_tag.indicator)). To conveniently generate many disjunctions at once, see @disjunction and @disjunctions.

source
DisjunctiveProgramming.make_disaggregated_variableMethod
make_disaggregated_variable(
     model::JuMP.AbstractModel, 
     vref::JuMP.AbstractVariableRef, 
     name::String, 
     lower_bound::Number, 
     upper_bound::Number
-    )::JuMP.AbstractVariableRef

Creates and adds a variable to model with name name and bounds lower_bound and upper_bound based on the original variable vref. This is used to create dissagregated variables needed for the Hull reformulation. This is implemented for model::JuMP.GenericModel and vref::JuMP.GenericVariableRef, but it serves as an extension point for interfaces with other model/variable reference types. This also requires the implementation of requires_disaggregation.

source
DisjunctiveProgramming.reformulate_disjunct_constraintMethod
reformulate_disjunct_constraint(
+    )::JuMP.AbstractVariableRef

Creates and adds a variable to model with name name and bounds lower_bound and upper_bound based on the original variable vref. This is used to create dissagregated variables needed for the Hull reformulation. This is implemented for model::JuMP.GenericModel and vref::JuMP.GenericVariableRef, but it serves as an extension point for interfaces with other model/variable reference types. This also requires the implementation of requires_disaggregation.

source
DisjunctiveProgramming.reformulate_disjunct_constraintMethod
reformulate_disjunct_constraint(
     model::JuMP.AbstractModel,  
     con::JuMP.AbstractConstraint, 
     bvref::JuMP.AbstractVariableRef,
     method::AbstractReformulationMethod
-)

Extension point for reformulation method method to reformulate disjunction constraint con over each constraint. If method needs to specify how to reformulate the entire disjunction, see reformulate_disjunction.

source
DisjunctiveProgramming.reformulate_disjunctionMethod
reformulate_disjunction(
     model::JuMP.AbstractModel, 
     disj::Disjunction,
     method::AbstractReformulationMethod
-) where {T<:Disjunction}

Reformulate a disjunction using the specified method. Current reformulation methods include BigM, Hull, and Indicator. This method can be extended for other reformulation techniques.

The disj field is the ConstraintData object for the disjunction, stored in the disjunctions field of the GDPData object.

source
DisjunctiveProgramming.reformulate_modelFunction
reformulate_model(model::JuMP.AbstractModel, method::AbstractSolutionMethod = BigM())

Reformulate a GDPModel using the specified method. Prior to reformulation, all previous reformulation variables and constraints are deleted.

source
DisjunctiveProgramming.requires_disaggregationMethod
requires_disaggregation(vref::JuMP.AbstractVariableRef)::Bool

Return a Bool whether vref requires disaggregation for the Hull reformulation. This is intended as an extension point for interfaces with DisjunctiveProgramming that use variable reference types that are not JuMP.GenericVariableRefs. Errors if vref is not a JuMP.GenericVariableRef. See also make_disaggregated_variable.

source
DisjunctiveProgramming.requires_exactly1Method
requires_exactly1(method::AbstractReformulationMethod)

Return a Bool whether method requires that Exactly 1 disjunct be selected as true for each disjunction. For new reformulation method types, this should be extended to return true if such a constraint is required (defaults to false otherwise).

source
DisjunctiveProgramming.set_variable_bound_infoFunction
set_variable_bound_info(vref, method::AbstractReformulationMethod)::Tuple{<:Number, <:Number}

Returns a tuple of the form (lower_bound, upper_bound) which are the bound information needed by method to reformulate disjunctions. This only needs to be implemented for methods where requires_variable_bound_info(method) = true. These bounds can later be accessed via variable_bound_info.

source
JuMP.add_constraintFunction
JuMP.add_constraint(
+) where {T<:Disjunction}

Reformulate a disjunction using the specified method. Current reformulation methods include BigM, Hull, and Indicator. This method can be extended for other reformulation techniques.

The disj field is the ConstraintData object for the disjunction, stored in the disjunctions field of the GDPData object.

source
DisjunctiveProgramming.reformulate_modelFunction
reformulate_model(model::JuMP.AbstractModel, method::AbstractSolutionMethod = BigM())

Reformulate a GDPModel using the specified method. Prior to reformulation, all previous reformulation variables and constraints are deleted.

source
DisjunctiveProgramming.requires_disaggregationMethod
requires_disaggregation(vref::JuMP.AbstractVariableRef)::Bool

Return a Bool whether vref requires disaggregation for the Hull reformulation. This is intended as an extension point for interfaces with DisjunctiveProgramming that use variable reference types that are not JuMP.GenericVariableRefs. Errors if vref is not a JuMP.GenericVariableRef. See also make_disaggregated_variable.

source
DisjunctiveProgramming.requires_exactly1Method
requires_exactly1(method::AbstractReformulationMethod)

Return a Bool whether method requires that Exactly 1 disjunct be selected as true for each disjunction. For new reformulation method types, this should be extended to return true if such a constraint is required (defaults to false otherwise).

source
DisjunctiveProgramming.set_variable_bound_infoFunction
set_variable_bound_info(vref, method::AbstractReformulationMethod)::Tuple{<:Number, <:Number}

Returns a tuple of the form (lower_bound, upper_bound) which are the bound information needed by method to reformulate disjunctions. This only needs to be implemented for methods where requires_variable_bound_info(method) = true. These bounds can later be accessed via variable_bound_info.

source
JuMP.add_constraintFunction
JuMP.add_constraint(
     model::JuMP.AbstractModel,
     con::_DisjunctConstraint,
     name::String = ""
-)::DisjunctConstraintRef

Extend JuMP.add_constraint to add a Disjunct to a GDPModel. The constraint is added to the GDPData in the .ext dictionary of the GDPModel.

source
JuMP.add_constraintMethod
function JuMP.add_constraint(
+)::DisjunctConstraintRef

Extend JuMP.add_constraint to add a Disjunct to a GDPModel. The constraint is added to the GDPData in the .ext dictionary of the GDPModel.

source
JuMP.add_constraintMethod
function JuMP.add_constraint(
     model::JuMP.GenericModel,
     c::JuMP.ScalarConstraint{_LogicalExpr, MOI.EqualTo{Bool}},
     name::String = ""
-)

Extend JuMP.add_constraint to allow creating logical proposition constraints for a GDPModel with the @constraint macro. Users should define logical constraints via the syntax @constraint(model, logical_expr := true).

source
JuMP.add_constraintMethod
function JuMP.add_constraint(
+)

Extend JuMP.add_constraint to allow creating logical proposition constraints for a GDPModel with the @constraint macro. Users should define logical constraints via the syntax @constraint(model, logical_expr := true).

source
JuMP.add_constraintMethod
function JuMP.add_constraint(
     model::JuMP.GenericModel,
     c::VectorConstraint{<:F, S},
     name::String = ""
-) where {F <: Vector{<:LogicalVariableRef}, S <: AbstractCardinalitySet}

Extend JuMP.add_constraint to allow creating logical cardinality constraints for a GDPModel with the @constraint macro.

source
JuMP.add_variableFunction
JuMP.add_variable(model::JuMP.Model, v::LogicalVariable, 
-                  name::String = "")::LogicalVariableRef

Extend JuMP.add_variable for LogicalVariables. This helps enable @variable(model, [var_expr], Logical).

source
JuMP.build_constraintMethod
JuMP.build_constraint(
+) where {F <: Vector{<:LogicalVariableRef}, S <: AbstractCardinalitySet}

Extend JuMP.add_constraint to allow creating logical cardinality constraints for a GDPModel with the @constraint macro.

source
JuMP.add_variableFunction
JuMP.add_variable(model::JuMP.Model, v::LogicalVariable, 
+                  name::String = "")::LogicalVariableRef

Extend JuMP.add_variable for LogicalVariables. This helps enable @variable(model, [var_expr], Logical).

source
JuMP.build_constraintMethod
JuMP.build_constraint(
     _error::Function,
     func,
     set::_MOI.AbstractScalarSet,
     tag::Disjunct
-)::_DisjunctConstraint

Extend JuMP.build_constraint to add constraints to disjuncts. This in combination with JuMP.add_constraint enables the use of @constraint(model, [name], constr_expr, tag), where tag is a Disjunct(::Type{LogicalVariableRef}). The user must specify the LogicalVariable to use as the indicator for the _DisjunctConstraint being created.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
+)::_DisjunctConstraint

Extend JuMP.build_constraint to add constraints to disjuncts. This in combination with JuMP.add_constraint enables the use of @constraint(model, [name], constr_expr, tag), where tag is a Disjunct(::Type{LogicalVariableRef}). The user must specify the LogicalVariable to use as the indicator for the _DisjunctConstraint being created.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
     _error::Function,
     func,
     set::MathOptInterface.Nonnegatives,
     tag::Disjunct
-)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
+)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
     _error::Function,
     func,
     set::MathOptInterface.Nonpositives,
     tag::Disjunct
-)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
+)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
     _error::Function,
     func,
     set::MathOptInterface.Zeros,
     tag::Disjunct
-)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
+)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
     _error::Function,
     func,
     set::Nonnegatives,
     tag::Disjunct
-)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
+)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
     _error::Function,
     func,
     set::Nonpositives,
     tag::Disjunct
-)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
+)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
JuMP.build_constraint(
     _error::Function,
     func,
     set::Zeros,
     tag::Disjunct
-)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
function JuMP.build_constraint(
+)::_DisjunctConstraint

Extend JuMP.build_constraint to add VectorConstraints to disjuncts.

source
JuMP.build_constraintMethod
function JuMP.build_constraint(
     _error::Function,
     func::AbstractVector{T},
     set::S
 ) where {T <: LogicalVariableRef, S <: Union{Exactly, AtLeast, AtMost}}

Extend JuMP.build_constraint to add logical cardinality constraints to a GDPModel. This in combination with JuMP.add_constraint enables the use of @constraint(model, [name], logical_expr in set), where set can be either of the following cardinality sets: AtLeast(n), AtMost(n), or Exactly(n).

Example

To select exactly 1 logical variable Y to be true, do (the same can be done with AtLeast(n) and AtMost(n)):

using DisjunctiveProgramming
 model = GDPModel();
 @variable(model, Y[i = 1:2], LogicalVariable);
-@constraint(model, [Y[1], Y[2]] in Exactly(1));
source
JuMP.build_variableMethod
JuMP.build_variable(_error::Function, info::JuMP.VariableInfo, 
-                    ::Union{Type{Logical}, Logical})

Extend JuMP.build_variable to work with logical variables. This in combination with JuMP.add_variable enables the use of @variable(model, [var_expr], Logical).

source
JuMP.constraint_objectMethod
JuMP.constraint_object(cref::DisjunctConstraintRef)

Return the underlying constraint data for the constraint referenced by cref.

source
JuMP.constraint_objectMethod
JuMP.constraint_object(cref::DisjunctionRef)

Return the underlying constraint data for the constraint referenced by cref.

source
JuMP.constraint_objectMethod
JuMP.constraint_object(cref::LogicalConstraintRef)

Return the underlying constraint data for the constraint referenced by cref.

source
JuMP.deleteMethod
JuMP.delete(model::JuMP.AbstractModel, cref::DisjunctConstraintRef)

Delete a disjunct constraint from the GDP model.

source
JuMP.deleteMethod
JuMP.delete(model::JuMP.AbstractModel, cref::DisjunctionRef)

Delete a disjunction constraint from the GDP model.

source
JuMP.deleteMethod
JuMP.delete(model::JuMP.AbstractModel, cref::LogicalConstraintRef)

Delete a logical constraint from the GDP model.

source
JuMP.deleteMethod
JuMP.delete(model::JuMP.AbstractModel, vref::LogicalVariableRef)::Nothing

Delete the logical variable associated with vref from the GDP model.

source
JuMP.fixMethod
JuMP.fix(vref::LogicalVariableRef, value::Bool)::Nothing

Fix a logical variable to a value. Update the fixing constraint if one exists, otherwise create a new one.

source
JuMP.fix_valueMethod
JuMP.fix_value(vref::LogicalVariableRef)::Bool

Return the value to which a logical variable is fixed.

source
JuMP.indexMethod
JuMP.index(cref::DisjunctConstraintRef)

Return the index constraint associated with cref.

source
JuMP.indexMethod
JuMP.index(cref::DisjunctionRef)

Return the index constraint associated with cref.

source
JuMP.indexMethod
JuMP.index(cref::LogicalConstraintRef)

Return the index constraint associated with cref.

source
JuMP.indexMethod
JuMP.index(vref::LogicalVariableRef)::LogicalVariableIndex

Return the index of logical variable that associated with vref.

source
JuMP.is_fixedMethod
JuMP.is_fixed(vref::LogicalVariableRef)::Bool

Return true if vref is a fixed variable. If true, the fixed value can be queried with fix_value.

source
JuMP.is_validMethod
JuMP.is_valid(model::JuMP.AbstractModel, cref::DisjunctConstraintRef)

Return true if cref refers to a valid constraint in the GDP model.

source
JuMP.is_validMethod
JuMP.is_valid(model::JuMP.AbstractModel, cref::DisjunctionRef)

Return true if cref refers to a valid constraint in the GDP model.

source
JuMP.is_validMethod
JuMP.is_valid(model::JuMP.AbstractModel, cref::LogicalConstraintRef)

Return true if cref refers to a valid constraint in the GDP model.

source
JuMP.is_validMethod
JuMP.is_valid(model::JuMP.AbstractModel, vref::LogicalVariableRef)::Bool

Return true if vref refers to a valid logical variable in GDP model.

source
JuMP.isequal_canonicalMethod
JuMP.isequal_canonical(v::LogicalVariableRef, w::LogicalVariableRef)::Bool

Return true if v and w refer to the same logical variable in the same GDP model.

source
JuMP.nameMethod
JuMP.name(cref::DisjunctConstraintRef)

Get a constraint's name attribute.

source
JuMP.nameMethod
JuMP.name(cref::DisjunctionRef)

Get a constraint's name attribute.

source
JuMP.nameMethod
JuMP.name(cref::LogicalConstraintRef)

Get a constraint's name attribute.

source
JuMP.nameMethod
JuMP.name(vref::LogicalVariableRef)::String

Get a logical variable's name attribute.

source
JuMP.owner_modelMethod
JuMP.owner_model(cref::DisjunctConstraintRef)

Return the model to which cref belongs.

source
JuMP.owner_modelMethod
JuMP.owner_model(cref::DisjunctionRef)

Return the model to which cref belongs.

source
JuMP.owner_modelMethod
JuMP.owner_model(cref::LogicalConstraintRef)

Return the model to which cref belongs.

source
JuMP.owner_modelMethod
JuMP.owner_model(vref::LogicalVariableRef)::JuMP.AbstractModel

Return the GDP model to which vref belongs.

source
JuMP.set_nameMethod
JuMP.set_name(cref::DisjunctConstraintRef, name::String)

Set a constraint's name attribute.

source
JuMP.set_nameMethod
JuMP.set_name(cref::DisjunctionRef, name::String)

Set a constraint's name attribute.

source
JuMP.set_nameMethod
JuMP.set_name(cref::LogicalConstraintRef, name::String)

Set a constraint's name attribute.

source
JuMP.set_nameMethod
JuMP.set_name(vref::LogicalVariableRef, name::String)::Nothing

Set a logical variable's name attribute.

source
JuMP.set_start_valueMethod
JuMP.set_start_value(vref::LogicalVariableRef, value::Union{Nothing, Bool})::Nothing

Set the start value of the logical variable vref.

Pass nothing to unset the start value.

source
JuMP.start_valueMethod
JuMP.start_value(vref::LogicalVariableRef)::Bool

Return the start value of the logical variable vref.

source
JuMP.unfixMethod
JuMP.unfix(vref::LogicalVariableRef)::Nothing

Delete the fixed value of a logical variable.

source
JuMP.valueMethod
JuMP.value(vref::LogicalVariableRef)::Bool

Returns the optimized value of vref. This dispatches on value(binary_variable(vref)) and then rounds to the closest Bool value.

source
DisjunctiveProgramming.BigMType
BigM{T} <: AbstractReformulationMethod

A type for using the big-M reformulation approach for disjunctive constraints.

Fields

  • value::T: Big-M value (default = 1e9).
  • tight::Bool: Attempt to tighten the Big-M value (default = true)?
source
DisjunctiveProgramming.ConstraintDataType
ConstraintData{C <: JuMP.AbstractConstraint}

A type for storing constraint objects in GDPData and any meta-data they possess.

Fields

  • constraint::C: The constraint.
  • name::String: The name of the proposition.
source
DisjunctiveProgramming.DisjunctType
Disjunct

Used as a tag for constraints that will be used in disjunctions. This is done via the following syntax:

julia> @constraint(model, [constr_expr], Disjunct)
+@constraint(model, [Y[1], Y[2]] in Exactly(1));
source
JuMP.build_variableMethod
JuMP.build_variable(_error::Function, info::JuMP.VariableInfo, 
+                    ::Union{Type{Logical}, Logical})

Extend JuMP.build_variable to work with logical variables. This in combination with JuMP.add_variable enables the use of @variable(model, [var_expr], Logical).

source
JuMP.constraint_objectMethod
JuMP.constraint_object(cref::DisjunctConstraintRef)

Return the underlying constraint data for the constraint referenced by cref.

source
JuMP.constraint_objectMethod
JuMP.constraint_object(cref::DisjunctionRef)

Return the underlying constraint data for the constraint referenced by cref.

source
JuMP.constraint_objectMethod
JuMP.constraint_object(cref::LogicalConstraintRef)

Return the underlying constraint data for the constraint referenced by cref.

source
JuMP.deleteMethod
JuMP.delete(model::JuMP.AbstractModel, cref::DisjunctConstraintRef)

Delete a disjunct constraint from the GDP model.

source
JuMP.deleteMethod
JuMP.delete(model::JuMP.AbstractModel, cref::DisjunctionRef)

Delete a disjunction constraint from the GDP model.

source
JuMP.deleteMethod
JuMP.delete(model::JuMP.AbstractModel, cref::LogicalConstraintRef)

Delete a logical constraint from the GDP model.

source
JuMP.deleteMethod
JuMP.delete(model::JuMP.AbstractModel, vref::LogicalVariableRef)::Nothing

Delete the logical variable associated with vref from the GDP model.

source
JuMP.fixMethod
JuMP.fix(vref::LogicalVariableRef, value::Bool)::Nothing

Fix a logical variable to a value. Update the fixing constraint if one exists, otherwise create a new one.

source
JuMP.fix_valueMethod
JuMP.fix_value(vref::LogicalVariableRef)::Bool

Return the value to which a logical variable is fixed.

source
JuMP.indexMethod
JuMP.index(cref::DisjunctConstraintRef)

Return the index constraint associated with cref.

source
JuMP.indexMethod
JuMP.index(cref::DisjunctionRef)

Return the index constraint associated with cref.

source
JuMP.indexMethod
JuMP.index(cref::LogicalConstraintRef)

Return the index constraint associated with cref.

source
JuMP.indexMethod
JuMP.index(vref::LogicalVariableRef)::LogicalVariableIndex

Return the index of logical variable that associated with vref.

source
JuMP.is_fixedMethod
JuMP.is_fixed(vref::LogicalVariableRef)::Bool

Return true if vref is a fixed variable. If true, the fixed value can be queried with fix_value.

source
JuMP.is_validMethod
JuMP.is_valid(model::JuMP.AbstractModel, cref::DisjunctConstraintRef)

Return true if cref refers to a valid constraint in the GDP model.

source
JuMP.is_validMethod
JuMP.is_valid(model::JuMP.AbstractModel, cref::DisjunctionRef)

Return true if cref refers to a valid constraint in the GDP model.

source
JuMP.is_validMethod
JuMP.is_valid(model::JuMP.AbstractModel, cref::LogicalConstraintRef)

Return true if cref refers to a valid constraint in the GDP model.

source
JuMP.is_validMethod
JuMP.is_valid(model::JuMP.AbstractModel, vref::LogicalVariableRef)::Bool

Return true if vref refers to a valid logical variable in GDP model.

source
JuMP.isequal_canonicalMethod
JuMP.isequal_canonical(v::LogicalVariableRef, w::LogicalVariableRef)::Bool

Return true if v and w refer to the same logical variable in the same GDP model.

source
JuMP.nameMethod
JuMP.name(cref::DisjunctConstraintRef)

Get a constraint's name attribute.

source
JuMP.nameMethod
JuMP.name(cref::DisjunctionRef)

Get a constraint's name attribute.

source
JuMP.nameMethod
JuMP.name(cref::LogicalConstraintRef)

Get a constraint's name attribute.

source
JuMP.nameMethod
JuMP.name(vref::LogicalVariableRef)::String

Get a logical variable's name attribute.

source
JuMP.owner_modelMethod
JuMP.owner_model(cref::DisjunctConstraintRef)

Return the model to which cref belongs.

source
JuMP.owner_modelMethod
JuMP.owner_model(cref::DisjunctionRef)

Return the model to which cref belongs.

source
JuMP.owner_modelMethod
JuMP.owner_model(cref::LogicalConstraintRef)

Return the model to which cref belongs.

source
JuMP.owner_modelMethod
JuMP.owner_model(vref::LogicalVariableRef)::JuMP.AbstractModel

Return the GDP model to which vref belongs.

source
JuMP.set_nameMethod
JuMP.set_name(cref::DisjunctConstraintRef, name::String)

Set a constraint's name attribute.

source
JuMP.set_nameMethod
JuMP.set_name(cref::DisjunctionRef, name::String)

Set a constraint's name attribute.

source
JuMP.set_nameMethod
JuMP.set_name(cref::LogicalConstraintRef, name::String)

Set a constraint's name attribute.

source
JuMP.set_nameMethod
JuMP.set_name(vref::LogicalVariableRef, name::String)::Nothing

Set a logical variable's name attribute.

source
JuMP.set_start_valueMethod
JuMP.set_start_value(vref::LogicalVariableRef, value::Union{Nothing, Bool})::Nothing

Set the start value of the logical variable vref.

Pass nothing to unset the start value.

source
JuMP.start_valueMethod
JuMP.start_value(vref::LogicalVariableRef)::Bool

Return the start value of the logical variable vref.

source
JuMP.unfixMethod
JuMP.unfix(vref::LogicalVariableRef)::Nothing

Delete the fixed value of a logical variable.

source
JuMP.valueMethod
JuMP.value(vref::LogicalVariableRef)::Bool

Returns the optimized value of vref. This dispatches on value(binary_variable(vref)) and then rounds to the closest Bool value.

source
DisjunctiveProgramming.BigMType
BigM{T} <: AbstractReformulationMethod

A type for using the big-M reformulation approach for disjunctive constraints.

Fields

  • value::T: Big-M value (default = 1e9).
  • tight::Bool: Attempt to tighten the Big-M value (default = true)?
source
DisjunctiveProgramming.ConstraintDataType
ConstraintData{C <: JuMP.AbstractConstraint}

A type for storing constraint objects in GDPData and any meta-data they possess.

Fields

  • constraint::C: The constraint.
  • name::String: The name of the proposition.
source
DisjunctiveProgramming.DisjunctType
Disjunct

Used as a tag for constraints that will be used in disjunctions. This is done via the following syntax:

julia> @constraint(model, [constr_expr], Disjunct)
 
-julia> @constraint(model, [constr_expr], Disjunct(lvref))

where lvref is a LogicalVariableRef that will ultimately be associated with the disjunct the constraint is added to. If no lvref is given, then one is generated when the disjunction is created.

source
DisjunctiveProgramming.DisjunctionType
Disjunction{M <: JuMP.AbstractModel} <: JuMP.AbstractConstraint

A type for a disjunctive constraint that is comprised of a collection of disjuncts of indicated by a unique LogicalVariableIndex.

Fields

  • indicators::Vector{LogicalVariableref}: The references to the logical variables

(indicators) that uniquely identify each disjunct in the disjunction.

  • nested::Bool: Is this disjunction nested within another disjunction?
source
DisjunctiveProgramming.GDPModelMethod
GDPModel([optimizer]; [kwargs...])::JuMP.Model
+julia> @constraint(model, [constr_expr], Disjunct(lvref))

where lvref is a LogicalVariableRef that will ultimately be associated with the disjunct the constraint is added to. If no lvref is given, then one is generated when the disjunction is created.

source
DisjunctiveProgramming.DisjunctionType
Disjunction{M <: JuMP.AbstractModel} <: JuMP.AbstractConstraint

A type for a disjunctive constraint that is comprised of a collection of disjuncts of indicated by a unique LogicalVariableIndex.

Fields

  • indicators::Vector{LogicalVariableref}: The references to the logical variables

(indicators) that uniquely identify each disjunct in the disjunction.

  • nested::Bool: Is this disjunction nested within another disjunction?
source
DisjunctiveProgramming.GDPModelMethod
GDPModel([optimizer]; [kwargs...])::JuMP.Model
 
 GDPModel{T}([optimizer]; [kwargs...])::JuMP.GenericModel{T}
 
-GDPModel{M <: JuMP.AbstractModel, VrefType, CrefType}([optimizer], [args...]; [kwargs...])::M

The core model object for building general disjunction programming models.

source
DisjunctiveProgramming.HullType
Hull{T} <: AbstractReformulationMethod

A type for using the convex hull reformulation approach for disjunctive constraints.

Fields

  • value::T: epsilon value for nonlinear hull reformulations (default = 1e-6).
source
DisjunctiveProgramming.LogicalType
Logical{T}

Tag for creating logical variables using @variable. Most often this will be used to enable the syntax:

@variable(model, var_expr, Logical, [kwargs...])

which creates a LogicalVariable that will ultimately be reformulated into a binary variable of the form:

@variable(model, var_expr, Bin, [kwargs...])

To include a tag that is used to create the reformulated variables, the syntax becomes:

@variable(model, var_expr, Logical(MyTag()), [kwargs...])

which creates a LogicalVariable that is associated with MyTag() such that the reformulation binary variables are of the form:

@variable(model, var_expr, Bin, MyTag(), [kwargs...])
source
DisjunctiveProgramming.LogicalVariableType
LogicalVariable <: JuMP.AbstractVariable

A variable type the logical variables associated with disjuncts in a Disjunction.

Fields

  • fix_value::Union{Nothing, Bool}: A fixed boolean value if there is one.
  • start_value::Union{Nothing, Bool}: An initial guess if there is one.
source
+GDPModel{M <: JuMP.AbstractModel, VrefType, CrefType}([optimizer], [args...]; [kwargs...])::M

The core model object for building general disjunction programming models.

source
DisjunctiveProgramming.HullType
Hull{T} <: AbstractReformulationMethod

A type for using the convex hull reformulation approach for disjunctive constraints.

Fields

  • value::T: epsilon value for nonlinear hull reformulations (default = 1e-6).
source
DisjunctiveProgramming.LogicalType
Logical{T}

Tag for creating logical variables using @variable. Most often this will be used to enable the syntax:

@variable(model, var_expr, Logical, [kwargs...])

which creates a LogicalVariable that will ultimately be reformulated into a binary variable of the form:

@variable(model, var_expr, Bin, [kwargs...])

To include a tag that is used to create the reformulated variables, the syntax becomes:

@variable(model, var_expr, Logical(MyTag()), [kwargs...])

which creates a LogicalVariable that is associated with MyTag() such that the reformulation binary variables are of the form:

@variable(model, var_expr, Bin, MyTag(), [kwargs...])
source
DisjunctiveProgramming.LogicalVariableType
LogicalVariable <: JuMP.AbstractVariable

A variable type the logical variables associated with disjuncts in a Disjunction.

Fields

  • fix_value::Union{Nothing, Bool}: A fixed boolean value if there is one.
  • start_value::Union{Nothing, Bool}: An initial guess if there is one.
source
diff --git a/dev/assets/documenter.js b/dev/assets/documenter.js index f531160..c6562b5 100644 --- a/dev/assets/documenter.js +++ b/dev/assets/documenter.js @@ -4,7 +4,6 @@ requirejs.config({ 'highlight-julia': 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/languages/julia.min', 'headroom': 'https://cdnjs.cloudflare.com/ajax/libs/headroom/0.12.0/headroom.min', 'jqueryui': 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min', - 'minisearch': 'https://cdn.jsdelivr.net/npm/minisearch@6.1.0/dist/umd/index.min', 'katex-auto-render': 'https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.8/contrib/auto-render.min', 'jquery': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min', 'headroom-jquery': 'https://cdnjs.cloudflare.com/ajax/libs/headroom/0.12.0/jQuery.headroom.min', @@ -103,9 +102,10 @@ $(document).on("click", ".docstring header", function () { }); }); -$(document).on("click", ".docs-article-toggle-button", function () { +$(document).on("click", ".docs-article-toggle-button", function (event) { let articleToggleTitle = "Expand docstring"; let navArticleToggleTitle = "Expand all docstrings"; + let animationSpeed = event.noToggleAnimation ? 0 : 400; debounce(() => { if (isExpanded) { @@ -116,7 +116,7 @@ $(document).on("click", ".docs-article-toggle-button", function () { isExpanded = false; - $(".docstring section").slideUp(); + $(".docstring section").slideUp(animationSpeed); } else { $(this).removeClass("fa-chevron-down").addClass("fa-chevron-up"); $(".docstring-article-toggle-button") @@ -127,7 +127,7 @@ $(document).on("click", ".docs-article-toggle-button", function () { articleToggleTitle = "Collapse docstring"; navArticleToggleTitle = "Collapse all docstrings"; - $(".docstring section").slideDown(); + $(".docstring section").slideDown(animationSpeed); } $(this).prop("title", navArticleToggleTitle); @@ -224,224 +224,465 @@ $(document).ready(function () { }) //////////////////////////////////////////////////////////////////////////////// -require(['jquery', 'minisearch'], function($, minisearch) { - -// In general, most search related things will have "search" as a prefix. -// To get an in-depth about the thought process you can refer: https://hetarth02.hashnode.dev/series/gsoc +require(['jquery'], function($) { -let results = []; -let timer = undefined; +$(document).ready(function () { + let meta = $("div[data-docstringscollapsed]").data(); -let data = documenterSearchIndex["docs"].map((x, key) => { - x["id"] = key; // minisearch requires a unique for each object - return x; + if (meta?.docstringscollapsed) { + $("#documenter-article-toggle-button").trigger({ + type: "click", + noToggleAnimation: true, + }); + } }); -// list below is the lunr 2.1.3 list minus the intersect with names(Base) -// (all, any, get, in, is, only, which) and (do, else, for, let, where, while, with) -// ideally we'd just filter the original list but it's not available as a variable -const stopWords = new Set([ - "a", - "able", - "about", - "across", - "after", - "almost", - "also", - "am", - "among", - "an", - "and", - "are", - "as", - "at", - "be", - "because", - "been", - "but", - "by", - "can", - "cannot", - "could", - "dear", - "did", - "does", - "either", - "ever", - "every", - "from", - "got", - "had", - "has", - "have", - "he", - "her", - "hers", - "him", - "his", - "how", - "however", - "i", - "if", - "into", - "it", - "its", - "just", - "least", - "like", - "likely", - "may", - "me", - "might", - "most", - "must", - "my", - "neither", - "no", - "nor", - "not", - "of", - "off", - "often", - "on", - "or", - "other", - "our", - "own", - "rather", - "said", - "say", - "says", - "she", - "should", - "since", - "so", - "some", - "than", - "that", - "the", - "their", - "them", - "then", - "there", - "these", - "they", - "this", - "tis", - "to", - "too", - "twas", - "us", - "wants", - "was", - "we", - "were", - "what", - "when", - "who", - "whom", - "why", - "will", - "would", - "yet", - "you", - "your", -]); - -let index = new minisearch({ - fields: ["title", "text"], // fields to index for full-text search - storeFields: ["location", "title", "text", "category", "page"], // fields to return with search results - processTerm: (term) => { - let word = stopWords.has(term) ? null : term; - if (word) { - // custom trimmer that doesn't strip @ and !, which are used in julia macro and function names - word = word - .replace(/^[^a-zA-Z0-9@!]+/, "") - .replace(/[^a-zA-Z0-9@!]+$/, ""); - } +}) +//////////////////////////////////////////////////////////////////////////////// +require(['jquery'], function($) { - return word ?? null; - }, - // add . as a separator, because otherwise "title": "Documenter.Anchors.add!", would not find anything if searching for "add!", only for the entire qualification - tokenize: (string) => string.split(/[\s\-\.]+/), - // options which will be applied during the search - searchOptions: { - boost: { title: 100 }, - fuzzy: 2, +/* +To get an in-depth about the thought process you can refer: https://hetarth02.hashnode.dev/series/gsoc + +PSEUDOCODE: + +Searching happens automatically as the user types or adjusts the selected filters. +To preserve responsiveness, as much as possible of the slow parts of the search are done +in a web worker. Searching and result generation are done in the worker, and filtering and +DOM updates are done in the main thread. The filters are in the main thread as they should +be very quick to apply. This lets filters be changed without re-searching with minisearch +(which is possible even if filtering is on the worker thread) and also lets filters be +changed _while_ the worker is searching and without message passing (neither of which are +possible if filtering is on the worker thread) + +SEARCH WORKER: + +Import minisearch + +Build index + +On message from main thread + run search + find the first 200 unique results from each category, and compute their divs for display + note that this is necessary and sufficient information for the main thread to find the + first 200 unique results from any given filter set + post results to main thread + +MAIN: + +Launch worker + +Declare nonconstant globals (worker_is_running, last_search_text, unfiltered_results) + +On text update + if worker is not running, launch_search() + +launch_search + set worker_is_running to true, set last_search_text to the search text + post the search query to worker + +on message from worker + if last_search_text is not the same as the text in the search field, + the latest search result is not reflective of the latest search query, so update again + launch_search() + otherwise + set worker_is_running to false + + regardless, display the new search results to the user + save the unfiltered_results as a global + update_search() + +on filter click + adjust the filter selection + update_search() + +update_search + apply search filters by looping through the unfiltered_results and finding the first 200 + unique results that match the filters + + Update the DOM +*/ + +/////// SEARCH WORKER /////// + +function worker_function(documenterSearchIndex, documenterBaseURL, filters) { + importScripts( + "https://cdn.jsdelivr.net/npm/minisearch@6.1.0/dist/umd/index.min.js" + ); + + let data = documenterSearchIndex.map((x, key) => { + x["id"] = key; // minisearch requires a unique for each object + return x; + }); + + // list below is the lunr 2.1.3 list minus the intersect with names(Base) + // (all, any, get, in, is, only, which) and (do, else, for, let, where, while, with) + // ideally we'd just filter the original list but it's not available as a variable + const stopWords = new Set([ + "a", + "able", + "about", + "across", + "after", + "almost", + "also", + "am", + "among", + "an", + "and", + "are", + "as", + "at", + "be", + "because", + "been", + "but", + "by", + "can", + "cannot", + "could", + "dear", + "did", + "does", + "either", + "ever", + "every", + "from", + "got", + "had", + "has", + "have", + "he", + "her", + "hers", + "him", + "his", + "how", + "however", + "i", + "if", + "into", + "it", + "its", + "just", + "least", + "like", + "likely", + "may", + "me", + "might", + "most", + "must", + "my", + "neither", + "no", + "nor", + "not", + "of", + "off", + "often", + "on", + "or", + "other", + "our", + "own", + "rather", + "said", + "say", + "says", + "she", + "should", + "since", + "so", + "some", + "than", + "that", + "the", + "their", + "them", + "then", + "there", + "these", + "they", + "this", + "tis", + "to", + "too", + "twas", + "us", + "wants", + "was", + "we", + "were", + "what", + "when", + "who", + "whom", + "why", + "will", + "would", + "yet", + "you", + "your", + ]); + + let index = new MiniSearch({ + fields: ["title", "text"], // fields to index for full-text search + storeFields: ["location", "title", "text", "category", "page"], // fields to return with results processTerm: (term) => { let word = stopWords.has(term) ? null : term; if (word) { + // custom trimmer that doesn't strip @ and !, which are used in julia macro and function names word = word .replace(/^[^a-zA-Z0-9@!]+/, "") .replace(/[^a-zA-Z0-9@!]+$/, ""); + + word = word.toLowerCase(); } return word ?? null; }, + // add . as a separator, because otherwise "title": "Documenter.Anchors.add!", would not + // find anything if searching for "add!", only for the entire qualification tokenize: (string) => string.split(/[\s\-\.]+/), - }, -}); + // options which will be applied during the search + searchOptions: { + prefix: true, + boost: { title: 100 }, + fuzzy: 2, + }, + }); -index.addAll(data); + index.addAll(data); + + /** + * Used to map characters to HTML entities. + * Refer: https://github.com/lodash/lodash/blob/main/src/escape.ts + */ + const htmlEscapes = { + "&": "&", + "<": "<", + ">": ">", + '"': """, + "'": "'", + }; + + /** + * Used to match HTML entities and HTML characters. + * Refer: https://github.com/lodash/lodash/blob/main/src/escape.ts + */ + const reUnescapedHtml = /[&<>"']/g; + const reHasUnescapedHtml = RegExp(reUnescapedHtml.source); + + /** + * Escape function from lodash + * Refer: https://github.com/lodash/lodash/blob/main/src/escape.ts + */ + function escape(string) { + return string && reHasUnescapedHtml.test(string) + ? string.replace(reUnescapedHtml, (chr) => htmlEscapes[chr]) + : string || ""; + } -let filters = [...new Set(data.map((x) => x.category))]; -var modal_filters = make_modal_body_filters(filters); -var filter_results = []; + /** + * Make the result component given a minisearch result data object and the value + * of the search input as queryString. To view the result object structure, refer: + * https://lucaong.github.io/minisearch/modules/_minisearch_.html#searchresult + * + * @param {object} result + * @param {string} querystring + * @returns string + */ + function make_search_result(result, querystring) { + let search_divider = `
`; + let display_link = + result.location.slice(Math.max(0), Math.min(50, result.location.length)) + + (result.location.length > 30 ? "..." : ""); // To cut-off the link because it messes with the overflow of the whole div + + if (result.page !== "") { + display_link += ` (${result.page})`; + } -$(document).on("keyup", ".documenter-search-input", function (event) { - // Adding a debounce to prevent disruptions from super-speed typing! - debounce(() => update_search(filter_results), 300); + let textindex = new RegExp(`${querystring}`, "i").exec(result.text); + let text = + textindex !== null + ? result.text.slice( + Math.max(textindex.index - 100, 0), + Math.min( + textindex.index + querystring.length + 100, + result.text.length + ) + ) + : ""; // cut-off text before and after from the match + + text = text.length ? escape(text) : ""; + + let display_result = text.length + ? "..." + + text.replace( + new RegExp(`${escape(querystring)}`, "i"), // For first occurrence + '$&' + ) + + "..." + : ""; // highlights the match + + let in_code = false; + if (!["page", "section"].includes(result.category.toLowerCase())) { + in_code = true; + } + + // We encode the full url to escape some special characters which can lead to broken links + let result_div = ` + +
+
${escape(result.title)}
+
${result.category}
+
+

+ ${display_result} +

+
+ ${display_link} +
+
+ ${search_divider} + `; + + return result_div; + } + + self.onmessage = function (e) { + let query = e.data; + let results = index.search(query, { + filter: (result) => { + // Only return relevant results + return result.score >= 1; + }, + }); + + // Pre-filter to deduplicate and limit to 200 per category to the extent + // possible without knowing what the filters are. + let filtered_results = []; + let counts = {}; + for (let filter of filters) { + counts[filter] = 0; + } + let present = {}; + + for (let result of results) { + cat = result.category; + cnt = counts[cat]; + if (cnt < 200) { + id = cat + "---" + result.location; + if (present[id]) { + continue; + } + present[id] = true; + filtered_results.push({ + location: result.location, + category: cat, + div: make_search_result(result, query), + }); + } + } + + postMessage(filtered_results); + }; +} + +// `worker = Threads.@spawn worker_function(documenterSearchIndex)`, but in JavaScript! +const filters = [ + ...new Set(documenterSearchIndex["docs"].map((x) => x.category)), +]; +const worker_str = + "(" + + worker_function.toString() + + ")(" + + JSON.stringify(documenterSearchIndex["docs"]) + + "," + + JSON.stringify(documenterBaseURL) + + "," + + JSON.stringify(filters) + + ")"; +const worker_blob = new Blob([worker_str], { type: "text/javascript" }); +const worker = new Worker(URL.createObjectURL(worker_blob)); + +/////// SEARCH MAIN /////// + +// Whether the worker is currently handling a search. This is a boolean +// as the worker only ever handles 1 or 0 searches at a time. +var worker_is_running = false; + +// The last search text that was sent to the worker. This is used to determine +// if the worker should be launched again when it reports back results. +var last_search_text = ""; + +// The results of the last search. This, in combination with the state of the filters +// in the DOM, is used compute the results to display on calls to update_search. +var unfiltered_results = []; + +// Which filter is currently selected +var selected_filter = ""; + +$(document).on("input", ".documenter-search-input", function (event) { + if (!worker_is_running) { + launch_search(); + } }); +function launch_search() { + worker_is_running = true; + last_search_text = $(".documenter-search-input").val(); + worker.postMessage(last_search_text); +} + +worker.onmessage = function (e) { + if (last_search_text !== $(".documenter-search-input").val()) { + launch_search(); + } else { + worker_is_running = false; + } + + unfiltered_results = e.data; + update_search(); +}; + $(document).on("click", ".search-filter", function () { if ($(this).hasClass("search-filter-selected")) { - $(this).removeClass("search-filter-selected"); + selected_filter = ""; } else { - $(this).addClass("search-filter-selected"); + selected_filter = $(this).text().toLowerCase(); } - // Adding a debounce to prevent disruptions from crazy clicking! - debounce(() => get_filters(), 300); + // This updates search results and toggles classes for UI: + update_search(); }); -/** - * A debounce function, takes a function and an optional timeout in milliseconds - * - * @function callback - * @param {number} timeout - */ -function debounce(callback, timeout = 300) { - clearTimeout(timer); - timer = setTimeout(callback, timeout); -} - /** * Make/Update the search component - * - * @param {string[]} selected_filters */ -function update_search(selected_filters = []) { - let initial_search_body = ` -
Type something to get started!
- `; - +function update_search() { let querystring = $(".documenter-search-input").val(); if (querystring.trim()) { - results = index.search(querystring, { - filter: (result) => { - // Filtering results - if (selected_filters.length === 0) { - return result.score >= 1; - } else { - return ( - result.score >= 1 && selected_filters.includes(result.category) - ); - } - }, - }); + if (selected_filter == "") { + results = unfiltered_results; + } else { + results = unfiltered_results.filter((result) => { + return selected_filter == result.category.toLowerCase(); + }); + } let search_result_container = ``; + let modal_filters = make_modal_body_filters(); let search_divider = `
`; if (results.length) { @@ -449,19 +690,23 @@ function update_search(selected_filters = []) { let count = 0; let search_results = ""; - results.forEach(function (result) { - if (result.location) { - // Checking for duplication of results for the same page - if (!links.includes(result.location)) { - search_results += make_search_result(result, querystring); - count++; - } - + for (var i = 0, n = results.length; i < n && count < 200; ++i) { + let result = results[i]; + if (result.location && !links.includes(result.location)) { + search_results += result.div; + count++; links.push(result.location); } - }); + } - let result_count = `
${count} result(s)
`; + if (count == 1) { + count_str = "1 result"; + } else if (count == 200) { + count_str = "200+ results"; + } else { + count_str = count + " results"; + } + let result_count = `
${count_str}
`; search_result_container = `
@@ -490,125 +735,37 @@ function update_search(selected_filters = []) { $(".search-modal-card-body").html(search_result_container); } else { - filter_results = []; - modal_filters = make_modal_body_filters(filters, filter_results); - if (!$(".search-modal-card-body").hasClass("is-justify-content-center")) { $(".search-modal-card-body").addClass("is-justify-content-center"); } - $(".search-modal-card-body").html(initial_search_body); + $(".search-modal-card-body").html(` +
Type something to get started!
+ `); } } /** * Make the modal filter html * - * @param {string[]} filters - * @param {string[]} selected_filters * @returns string */ -function make_modal_body_filters(filters, selected_filters = []) { - let str = ``; - - filters.forEach((val) => { - if (selected_filters.includes(val)) { - str += `${val}`; - } else { - str += `${val}`; - } - }); +function make_modal_body_filters() { + let str = filters + .map((val) => { + if (selected_filter == val.toLowerCase()) { + return `${val}`; + } else { + return `${val}`; + } + }) + .join(""); - let filter_html = ` + return `
Filters: ${str} -
- `; - - return filter_html; -} - -/** - * Make the result component given a minisearch result data object and the value of the search input as queryString. - * To view the result object structure, refer: https://lucaong.github.io/minisearch/modules/_minisearch_.html#searchresult - * - * @param {object} result - * @param {string} querystring - * @returns string - */ -function make_search_result(result, querystring) { - let search_divider = `
`; - let display_link = - result.location.slice(Math.max(0), Math.min(50, result.location.length)) + - (result.location.length > 30 ? "..." : ""); // To cut-off the link because it messes with the overflow of the whole div - - if (result.page !== "") { - display_link += ` (${result.page})`; - } - - let textindex = new RegExp(`\\b${querystring}\\b`, "i").exec(result.text); - let text = - textindex !== null - ? result.text.slice( - Math.max(textindex.index - 100, 0), - Math.min( - textindex.index + querystring.length + 100, - result.text.length - ) - ) - : ""; // cut-off text before and after from the match - - let display_result = text.length - ? "..." + - text.replace( - new RegExp(`\\b${querystring}\\b`, "i"), // For first occurrence - '$&' - ) + - "..." - : ""; // highlights the match - - let in_code = false; - if (!["page", "section"].includes(result.category.toLowerCase())) { - in_code = true; - } - - // We encode the full url to escape some special characters which can lead to broken links - let result_div = ` - -
-
${result.title}
-
${result.category}
-
-

- ${display_result} -

-
- ${display_link} -
-
- ${search_divider} - `; - - return result_div; -} - -/** - * Get selected filters, remake the filter html and lastly update the search modal - */ -function get_filters() { - let ele = $(".search-filters .search-filter-selected").get(); - filter_results = ele.map((x) => $(x).text().toLowerCase()); - modal_filters = make_modal_body_filters(filters, filter_results); - update_search(filter_results); +
`; } }) @@ -635,103 +792,107 @@ $(document).ready(function () { //////////////////////////////////////////////////////////////////////////////// require(['jquery'], function($) { -let search_modal_header = ` - -`; - -let initial_search_body = ` -
Type something to get started!
-`; - -let search_modal_footer = ` - -`; - -$(document.body).append( - ` - +# Y[2] binary

Contributing

DisjunctiveProgramming is being actively developed and suggestions or other forms of contribution are encouraged. There are many ways to contribute to this package. Feel free to create an issue to address questions or provide feedback.

diff --git a/dev/objects.inv b/dev/objects.inv new file mode 100644 index 0000000..1b5e1bf Binary files /dev/null and b/dev/objects.inv differ