
jcm_optimizer_path = '<JCM_OPTIMIZER_PATH>';
addpath(fullfile(jcm_optimizer_path, 'interface', 'matlab'));
 
server = jcmoptimizer.Server();
client = jcmoptimizer.Client(server.port); 

% Definition of the search domain
design_space = { ...
    struct('name', 'x1', 'type', 'continuous', 'domain', [-1.5,1.5]), ...
    struct('name', 'x2', 'type', 'continuous', 'domain', [-1.5,1.5]) ...
x};

% Definition of fixed environment parameter
environment = {...     
   struct('name', 'radius', 'type', 'fixed', 'domain', 1.5) ...
};

% Definition of a constraint on the search domain
constraints = {...
   struct('name', 'circle', 'expression', 'sqrt(x1^2 + x2^2) <= radius')...
};

 % Creation of the study object with study_id 'differential_evolution'
study = client.create_study( ...
    'design_space', design_space, ...
    'environment', environment, ...
    'constraints', constraints,...
    'driver','DifferentialEvolution',...
    'name','Global minimization of a non-expensive scalar function',...
    'study_id', 'differential_evolution');

% Configure study parameters
study.configure('max_iter', 80);

% Evaluation of the black-box function for specified design parameters
function observation = evaluate(study, sample)

    observation = study.new_observation();
    observation.add(10*2 ...
                    + (sample.x1^2 - 10*cos(2*pi*sample.x1)) ...
                    + (sample.x2^2 - 10*cos(2*pi*sample.x2)) ...
                   );
    
end  

% Run the minimization
study.set_evaluator(@evaluate);
study.run(); 

best = study.driver.best_sample;
fprintf('Best sample at x1=%0.3e, x2=%0.3e\n', best.x1, best.x2) 
