Skip to content

SetVariableBound() works for floats, not int #18

@mzagorowska

Description

@mzagorowska

This works:

obj(x) = x'*[2 1;1 4]*x + x'*[1;4] + 7;
p = DSProblem(2; objective=obj, initial_point=[1.0,2.0]);
SetVariableBound(p, 1, -1.0, 1.0) ####This line is important
SetGranularity(p, Dict( 1 => 0.1, 2 => 0.2 ))
Optimize!(p)

But this doesn't

obj(x) = x'*[2 1;1 4]*x + x'*[1;4] + 7;
p = DSProblem(2; objective=obj, initial_point=[1.0,2.0]);
SetVariableBound(p, 1, -1, 1) ####This line is important - same bounds but ints
SetGranularity(p, Dict( 1 => 0.1, 2 => 0.2 ))
Optimize!(p)

And gives an error:
image

Not sure if this is a bug or just a documentation issue, see https://imperialcollegelondon.github.io/DirectSearch.jl/dev/man/usage/#Variable-Bounds-1

Edit:
Strangely enough, for multiple bounds at least one value in each vector needs to be a float. This works:

obj(x) = x'*[2 1;1 4]*x + x'*[1;4] + 7;
p = DSProblem(2; objective=obj, initial_point=[1.0,2.0]);
SetVariableBounds(p, [-1, -1.0], [2.0 ,2])
SetGranularity(p, Dict( 1 => 0.1, 2 => 0.2 ))
Optimize!(p)

This doesn't:

obj(x) = x'*[2 1;1 4]*x + x'*[1;4] + 7;
p = DSProblem(2; objective=obj, initial_point=[1.0,2.0]);
SetVariableBounds(p, [-1, -1], [2.0 ,2])
SetGranularity(p, Dict( 1 => 0.1, 2 => 0.2 ))
Optimize!(p)

and gives:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions