# TOMNET  
# REGISTER (TOMNET)
# LOGIN  
# myTOMNET
TOMLAB LOGO

« Previous « Start » Next »

9  GLB Problem

The unconstrained global optimization (glb) problem is defined as
 
min
x
f(x)
   
s/t
−∞ < xL x xU < ∞
    (11)
where x, xL, xU ∈ Rn, f(x) ∈ R.

The following file (maintained from the solution file: quickguide/glbQG/glbQG.sln) illustrates how to solve an unconstrained global optimization problem in TOMNET.
using System;
using TOMNET;

namespace TOMNET
{
  /// <summary>
  /// Quick guide class for unconstrained global optimization (glb).
  /// </summary>
  public static class glbQG
  {
    /// <summary>
    /// Computes function value for Shekel 5.
    /// </summary>
    private class glbQG_f : IFunction
    {
      //
      // Constants used by objective function
      //
      const int ACols = 4;
      const int ARows = 5;
      double[] c = new double[ARows] { 0.1, 0.2, 0.2, 0.4, 0.4 };
      double[] A = new double[ACols * ARows] { 4.0, 4.0, 4.0, 4.0,
        1.0, 1.0, 1.0, 1.0,
        8.0, 8.0, 8.0, 8.0,
        6.0, 6.0, 6.0, 6.0,
        3.0, 7.0, 3.0, 7.0 };

      //
      // The objective function
      //
      public void Evaluate(double[] f, double[] x)
      {
        f[0] = 0.0;
        double xai = 0.0;
        for (int i = 0; i < ARows; i++)
        {
          xai = 0.0;
          for (int j = 0; j < ACols; j++)
          {
            xai += Math.Pow(x[j] - A[i * ACols + j], 2);
          }

          f[0] -= 1.0 / (xai + c[i]);
        }
      }
    }

    /// <summary>
    /// Creates and returns a glbProblem.
    /// </summary>
    /// <returns>glbProblem.</returns>
    public static NonlinearProblem getGlbQG()
    {
      //
      // Name of the problem
      //
      string Name = "glbQG";

      //
      // Number of decision variables.
      //
      const int N = 4;

      //
      // Lower and upper bounds for decision variables as well
      // as the starting point for the solver.
      //
      double[] x_L = new double[N] { 0, 0, 0, 0};
      double[] x_U = new double[N] { 10, 10, 10, 10};
      double[] x_0 = new double[N] { 1, 2, 4, 8};

      //
      // Information about Optimum.
      //
      double[] f_opt = new double[1] {-10.1531996790582};
      double f_Low = -20.0;

      //
      // Objective function instance.
      //
      glbQG_f F = new glbQG_f();

      //
      // Create an instance of the unconstrained problem
      //
      return new NonlinearProblem(F, null, null, null, x_L, x_U,
          x_0, Name, f_Low, f_opt, null);
    }

    /// <summary>
    /// Testprogram for glbQG.
    /// </summary>
    static void Main(string[] args)
    {
      //
      // Create a problem, solver and result instance.
      //
      NonlinearProblem Prob = getGlbQG();
      SNOPT solver = new SNOPT();
      Result result;

      //
      // Define a print file for SNOPT
      //
      string printfilename = "SnoptGlbQG.txt";
      solver.Options.PrintFile = printfilename;

      //
      // Solve the problem
      //
      solver.Solve(Prob, out result);

      //
      // Display the solution on the console.
      //
      Console.WriteLine(" * * * * * * * *");
      Console.WriteLine(" * Solved a glb problem with SNOPT");
      Console.WriteLine(" * Printfile: " + printfilename);
      Console.WriteLine(" * Objective: {0,10:F6}", result.f_k);
      Console.WriteLine(" * Solution");
      Console.WriteLine("        x_L[i] <=     x_k[i] <=     x_U[i]");
      for (int i = 0; i < Prob.N; i++)
      {
        Console.WriteLine("    {0,10:F6} <= {1,10:F6} <= {2,10:F6} ",
          Prob.x_L[i], result.x_k[i], Prob.x_U[i]);
      }
    }
  }
}
Only the objective function can be defined for unconstrained (box-bounded) problems:
  f:   Function
The following results should be displayed after running the executable:

« Previous « Start » Next »