13.8.2. Macro “reoptimizeHollowBarCodeMultiStart.C

13.8.2.1. Objective

The objective of the macro is to optimize the section of the hollow bar defined in Sizing of a hollow bar example problem using the NLopt solvers (reducing it to a single-criterion optimisation as already explained in Local solver. It is largely based on the previous macro, the main change being the fact that we allow different starting points.

13.8.2.2. Macro Uranie

    using namespace URANIE::DataServer;
    using namespace URANIE::Relauncher;
    using namespace URANIE::Reoptimizer;

    // variables
    TAttribute x("x", 0.0, 1.0),
      y("y", 0.0, 1.0),
      thick("thick"), // thickness
      sect("sect"), // section of the pipe
      dist("dist"); // distortion

    // Creating the TCodeEval, dumping output of the dummy python in an output file
    string python_exec = "python3";
    if(string(gSystem->GetBuildArch()) == "win64")
        python_exec.pop_back();
    TCodeEval code((python_exec + " bar.py > bartoto.dat").data());

    // Pass the python script itself as a input file. x and y will be modified in bar.py directly
    TKeyScript inputfile("bar.py");
    inputfile.addInput(&x,"x");
    inputfile.addInput(&y,"y");
    code.addInputFile(&inputfile);

    // precise the name of the output file in which to read the three output variables
    TFlatResult outputfile("bartoto.dat");
    outputfile.addOutput(&thick);
    outputfile.addOutput(&sect);
    outputfile.addOutput(&dist);
    code.addOutputFile(&outputfile);

    // Create a runner
    TSequentialRun runner(&code);
    runner.startSlave(); // Usual Relauncher construction

    if(runner.onMaster())
    {
        // Create the TDS
        TDataServer tds("vizirDemo", "Param de l'opt vizir pour la barre");
        tds.addAttribute(&x);
        tds.addAttribute(&y);

        // Choose a solver
        TNloptCobyla solv;
        //TNloptBobyqa solv;
        //TNloptPraxis solv;
        //TNloptNelderMead solv;
        ///TNloptSubplexe solv;

        // Create the single-objective constrained optimizer
        TNlopt opt(&tds, &runner, &solv);

        // add the objective
        opt.addObjective(&sect); // minimizing the section

	    // and the constrains
        TLesserFit constrDist(14);
        opt.addConstraint(&dist,&constrDist); // on the distortion (dist < 14)
        TGreaterFit positiv(0.4);
        opt.addConstraint(&thick,&positiv); // and on the thickness (thick > 0.4)

        // Starting points
        vector<double> p1{0.9 , 0.2}, p2{0.7 , 0.1}, p3{0.5 , 0.4};
        opt.setStartingPoint(p1.size(),&p1[0]);
        opt.setStartingPoint(p2.size(),&p2[0]);
        opt.setStartingPoint(p3.size(),&p3[0]);

        // Set maximum evaluation
        opt.setMaximumEval(1000);

        opt.solverLoop(); // running the optimization

        // Stop the slave processes
        runner.stopSlave();

        // solution
        tds.getTuple()->Scan("*","","colsize=9 col=:::5:4");
    }

As stated previously, the purpose of this macro is to use different starting points for optimisation fully based on the macro shown in Macro “reoptimizeHollowBarCode.C”. The only difference is highlighted here:

        // Starting points
        vector<double> p1{0.9 , 0.2}, p2{0.7 , 0.1}, p3{0.5 , 0.4};
        opt.setStartingPoint(p1.size(),&p1[0]);
        opt.setStartingPoint(p2.size(),&p2[0]);
        opt.setStartingPoint(p3.size(),&p3[0]);

The results of this is that optimisation is performed three times, using the three starting points provided. Here it is done sequentially, but obviously, the main idea is that it is a convenient way to parallelise these optimisation. This could be done for instance, simply by changing the runner line from

    TSequentialRun runner(&code);

to, for instance in our case with 3 starting points

TThreadedRun runner(&code,4);

13.8.2.3. Console

This macro leads to the following result

--- Uranie v4.11/0 --- Developed with ROOT (6.36.06)
                      Copyright (C) 2013-2026 CEA/DES 
                      Contact: support-uranie@cea.fr 
                      Date: Thu Feb 12, 2026

|....:....|....:....|....:....|....:....|....:....0050
|....:....|....:....
|....:....|....:....|....:....0100
|..
..:....|....:....|....:...
***************************************************************************
*    Row   * vizirDemo *       x.x *       y.y * thick * sect * dist.dist *
***************************************************************************
*        0 *         0 * 0.5173155 * 0.1173213 * 0.399 * 0.25 * 14.000005 *
*        1 *         1 * 0.5173156 * 0.1173173 * 0.399 * 0.25 * 13.999986 *
*        2 *         2 * 0.5173155 * 0.1173155 *   0.4 * 0.25 *        14 *
***************************************************************************