Question

I'm using an optimization library (NLOpt, written for c++) in c#, via this wrapper:

https://github.com/roryclune/NLOptDotNet

When adding more than 15 constraints to the problem I get a SEHException. Constraints are added by passing a FunctionDelegate to the solver.

This is the exception stacktrace: System.Runtime.InteropServices.SEHException (0x80004005): External component has thrown an exception. at _CxxThrowException(Void* , s_ThrowInfo* ) at nlopt.opt.mythrow(opt* , nlopt_result ret) at nlopt.opt.add_equality_constraint(opt* , IntPtr vf, Void* f_data, Double tol) at NLOptDotNet.NLOptWrapper.AddFunction(FunctionType ftype, FunctionDelegate funcDelegate, Object data, Double tol)

Am I missing something or is it necessarily a bug in the wrapper\library? Here's the code, I get the exception at the --->>> line:

   public NetDescriptor optimize(NetDescriptor netDescriptor){


        //The optimization algorithm
        Algorithm main_alg = Algorithm.LD_SLSQP;

        //Create optimization object, setting algorithm type and number of variables
        NLOptWrapper wrapper = new NLOptWrapper(main_alg, arcsNumber*2);
        wrapper.VERBOSE_OUTPUT = false;


        //Set stopping criteria
        wrapper.MaxTime = 60;          
        wrapper.XTolRelative = 1e-8;
        wrapper.FTolAbsolute = 1e-8;
        wrapper.MaxEval = 5000;
        wrapper.StopVal = 0;


        //Set lower and upper bounds
        double[] x = new double[arcsNumber*2];
        for(int i = 0; i < arcsNumber*2; i++)
            x[i] = 1e-8;

        wrapper.SetLowerBounds(x);


        for(int i = 0; i < arcsNumber*2; i+=2) {
            x[i] = 1e8;
            x[i+1] = 1;
        }

        wrapper.SetUpperBounds(x);




        //FLOW AND MIX BALANCE CONSTRAINTS
        for (int i = 1; i < (nodesNumber - 1); i++) {

            ArrayList inArcs = (nodes[i] as Node).getInArcs();
            ArrayList outArcs = (nodes[i] as Node).getOutArcs();
            int[] coefficients = new int[arcsNumber];

            for (int j = 0; j < arcsNumber; j++)
                coefficients[j] = 0;


            foreach(Arc a in inArcs)
                coefficients[a.getIndex()] = 1;

            foreach (Arc a in outArcs)
                coefficients[a.getIndex()] = -1;


            flowBalanceData FBD = new flowBalanceData(coefficients);

       -->>>     wrapper.AddEqualityConstraint(new FunctionDelegate(flowBalanceConstraint), FBD, 1e-2);

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top