Hello there

I have been using NLopt in Delphi utilizing the dll's released on
http://ab-initio.mit.edu/wiki/index.php/NLopt_on_Windows.

Combining constraints (i.e. using nlopt_add_inequality_(m)constraint) with
AUGLAG as a "shell algorithm" and a given subsidiary algorithm (i.e. using
nlopt_set_local_optimizer), I am experiencing an "Invalid floating point
operation" when the constraint evaluation is not violated (that is, when
the constraint function value, representing the left-hand side, is negative
such that LHS<=0). At the bottom of this mail, i provide a simple example
where the problem appears.

Note that the problem reminds very much of the post by Ernest Adrogué 25
June 2014 (
https://www.mail-archive.com/[email protected]/msg00611.html).

In order to debug the problem, a friend of mine has managed to compile a
32-bit NLopt dll himself, but when I use this, the error is gone! However,
he has also compiled a 64-bit dll, but this gives the same error as the
official dll's.

Thus, to me it seems that the problem is that the official dll's are not
correctly compiled. Could this be the case, and if so, can it be fixed more
or less easily?

Best regards
Claus Hedegaard-Hansen



*Delphi example:*
*--------------------------*
function ObjectiveFunc(n: Cardinal; x,gradient: PDoubleArray; PfData:
Pointer): double; cdecl;
begin
  Result := x[0]*x[0]-1;
end;

function ConstraintFunc(n: Cardinal; x,gradient: PDoubleArray; PfData:
Pointer): double; cdecl;
begin
  Result := x[0]-2; //"Invalid floating point operation" when Result <=0!
end;

procedure TForm1.Optimize(Sender: TObject);
var
  alg: TNLoptAlgorithm;
  algS: TNLoptAlgorithm;
  opt: NLopt_opt;
  optS: NLopt_opt;
  dim: Integer;
  constrTolerance: Double;
  x: TDoubleArray;
  fData: PDoubleArray;
  objectiveFuncVal: Double;
  supplySubAlg: Boolean;
  addConstraint: Boolean;
begin
  dim := 1;
  constrTolerance := 0.00001;

  //Starting value(s)
  x[0] := 1;

  // When both are True: "Invalid floating point operation"!
  supplySubAlg := True;
  addConstraint := True;

  LoadNLopt;
  try
    // Supply subsudiary algorithm (set_local_optimizer)?
    if supplySubAlg then
    begin
      alg := NLOPT_AUGLAG;
      algS := NLOPT_LN_NELDERMEAD;
      opt := nlopt_create(alg, dim);
      optS := nlopt_create(algS, dim);
      nlopt_set_maxeval(optS, 1000);
      nlopt_set_local_optimizer(opt, optS);
      nlopt_destroy(optS);
    end
    else
    begin
      alg := NLOPT_LN_COBYLA;
      opt := nlopt_create(alg, dim);
    end;

    nlopt_set_min_objective(opt, ObjectiveFunc, @fData);
    if addConstraint then
      nlopt_add_inequality_constraint(opt, ConstraintFunc, @fData,
constrTolerance);
    nlopt_set_maxeval(opt, 100);
    nlopt_optimize(opt, @x, objectiveFuncVal);
  finally
    nlopt_destroy(opt);
  end;
end;
_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss

Reply via email to