
optimize(+Objective, -Cost)
EplexInstance:optimize(+Objective, -Cost)

   Setup problem, solve and instantiate problem variables

Arguments
   Objective           Objective function: min(CostExpr) or max(CostExpr)
   Cost                Output: cost of returned solution

Type
   library(eplex)

Description

    Take the problem defined by all the constraints that have been set up
    so far, and solve it for the given objective function.  If successful,
    instantiate all problem variables to their solution values.

    This is a convenience predicate that combines solver setup, invocation
    and result retrieval.  It is essentially defined as:
    
    optimize(OptExpr, Cost) :-
        eplex_solver_setup(OptExpr),
        eplex_solve(Cost),
        eplex_get(vars, VArr),
        eplex_get(typed_solution, SolutionVector),
        VArr = SolutionVector.                  % do the bindings
    

    

Examples
   
    :- lib(eplex).

    main(Cost, Supply) :-
        data(PlantCapacities, ClientDemands, TranspCosts),
        dim(TranspCosts, [NClients,NPlants]),   % get dimensions

        dim(Supply, [NClients,NPlants]),        % make variables
        Supply :: 0.0..inf,                     % initial bounds

        ( for(J,1,NClients), param(ClientDemands,Supply) do
            sum(Supply[J,*]) $= ClientDemands[J]
        ),

        ( for(I,1,NPlants), param(PlantCapacities,Supply) do
            sum(Supply[*,I]) $=< PlantCapacities[I]
        ),

        Objective = sum(concat(TranspCosts)*concat(Supply)),

        optimize(min(Objective), Cost).         % solve

    data(
        [](500, 300, 400),              % PlantCapacities
        [](200, 400, 300, 100),         % ClientDemands
        []([](10, 7, 11),               % TranspCosts
           []( 8, 5, 10),
           []( 5, 5,  8),
           []( 9, 3,  7))
    ).


See Also
   $= / 2, $=< / 2, $>= / 2, $:: / 2, integers / 1, reals / 1, eplex_solver_setup / 1, eplex_solve / 1, eplex_get / 2, eplex_var_get / 3, optimize / 3
