% This program implements the Case Study % CS_Project_Selection_FXCHG with mpsg_solver %------------------------------------------------------------------------ %Solving Problem 1 (linear) %Clear workspace clear; global psg_suppress_message; psg_suppress_message = true; %load data load('CS_Project_Selection_FXCHG_psg_solver_data.mat'); %Specify the set of values of upper bound on available initial capital UB_Init_Capital = [300 350 400 500 600 650]; Points (7,6) =0; Objectives(6) =0; %Type fixed elements of problem statement str1 = sprintf('Problem: problem_CS_Project_Selection_linear, type = maximize'); str2 = sprintf('Objective: objective_Project_Selection_linear'); str3 = sprintf('linear_npv(matrix_CS_Project_Selection_npv)'); str5 = sprintf('linear_costs(matrix_CS_Project_Selection_costs)'); str6 = sprintf('Box_of_Variables: lowerbounds = point_lowerbounds, upperbounds = point_upperbounds , types = 1'); str7 = sprintf('Solver: VAN, precision = 6'); %Begin loop for Optimization Problem 1 over parameter values for i=1:1:length(UB_Init_Capital) %Generate parameter-specific fragment of the problem description str4 = sprintf('%s%.6f','Constraint: constraint_budget_linear, upper_bound = ',UB_Init_Capital(i),', linearize = 1'); %Generate problem statement clear problem_statement; problem_statement = sprintf('%s\n', str1, str2, str3, str4, str5, str6, str7); % Call the solver [solution_str, outargstruc_arr] = mpsg_solver(problem_statement, iargstruc_arr); %Extract optimal solution optimal_point = get_optimalpoint(solution_str, iargstruc_arr, outargstruc_arr); point_variables = optimal_point(:, 1); for j=1:1:size(optimal_point,1) Points_Problem_1(j,i)= optimal_point{j,2}; end obj_function_value=get_solution(solution_str, outargstruc_arr, 'objective_Project_Selection_linear'); constr_function_value=get_solution(solution_str, outargstruc_arr, 'constraint_budget_linear'); Objectives(i) = obj_function_value; % Get optimal point temp1 = get_solution(solution_str, outargstruc_arr, 'optimal_point'); temp2=temp1(:,2); optimal_point=cell2mat(temp2); Points(:,i) = optimal_point; z=size(optimal_point); end %Prepare output values and display them in the Command Window project_name = cell2mat(point_variables); fprintf('\n%12s','Table 1: Solution of Problem 1 (linear)'); fprintf('\n%12s','UB_Init_Capital'); for i=1:1:length(UB_Init_Capital) fprintf('%12.0f', UB_Init_Capital(i)); end fprintf('\n%5s','Objective '); for i=1:1:length(UB_Init_Capital) fprintf('%12.4f', Objectives(i)); end fprintf('\n%5s','Optimal points'); fprintf('\n%5s','Project'); for j=1:length(Points(:,1)) fprintf('\n%8s', project_name (j,:)); fprintf(' '); for i=1:1:length(UB_Init_Capital) fprintf('%12f', Points(j,i)); end end fprintf('\n'); fprintf('\n'); %Create plots for output subplot(2,1,1); plot2 = plot(UB_Init_Capital, Objectives, '-ob', 'LineWidth', 1.5, 'MarkerFaceColor', 'b', 'MarkerSize', 3); title('Objective vs Parameter: linear', 'FontSize', 12); xlabel('Parameter'); ylabel('Objectives'); grid on; %-------------------------------------------------------------------------- %Solving Problem 2 (fxchg_pos) %Clear workspace clear; mpsg_suppress_message('On'); % PSG messages are swithced off mpsg_suppress_warning('On'); % PSG warnings are swithced off %load data load('CS_Project_Selection_FXCHG_psg_solver_data.mat'); %Specify the set of values of upper bound on available initial capital UB_Init_Capital = [300 350 400 500 600 650]; Points (7,6) =0; Objectives(6) =0; %Define problem statement str1 = sprintf('Problem: problem_CS_Project_Selection_FXCHG, type = maximize'); str2 = sprintf('Objective: objective_Project_Selection_FXCHG'); str3 = sprintf('linear_npv(matrix_cs_project_selection_npv)'); str5 = sprintf('fxchg_pos_costs(0.00000010, matrix_cs_project_selection_costs)'); str6 = sprintf('Box_of_Variables: lowerbounds = point_lowerbounds, upperbounds = point_upperbounds'); str7 = sprintf('Solver: VAN, precision = 6, stages = 6'); %Begin loop for Optimization Problem 2 over parameter values for i=1:1:length(UB_Init_Capital) %Generate parameter-specific fragment of the problem description str4 = sprintf('%s%.6f','Constraint: constraint_budget, upper_bound = ',UB_Init_Capital(i),', linearize = 1'); %Generate problem statement clear problem_statement; problem_statement = sprintf('%s\n', str1, str2, str3, str4, str5, str6, str7); % Call the solver [solution_str, outargstruc_arr] = mpsg_solver(problem_statement, iargstruc_arr); %Extract optimal solution optimal_point = get_optimalpoint(solution_str, iargstruc_arr, outargstruc_arr); point_variables = optimal_point(:, 1); for j=1:1:size(optimal_point,1) Points_Problem_1(j,i)= optimal_point{j,2}; end obj_function_value=get_solution(solution_str, outargstruc_arr, 'objective_Project_Selection_FXCHG'); constr_function_value=get_solution(solution_str, outargstruc_arr, 'constraint_budget'); Objectives(i) = obj_function_value; % Get optimal point temp1 = get_solution(solution_str, outargstruc_arr, 'optimal_point'); temp2=temp1(:,2); optimal_point=cell2mat(temp2); Points(:,i) = optimal_point; z=size(optimal_point); end %Prepare output values and display them in the Command Window project_name = cell2mat(point_variables); fprintf('\n%12s','Table 2: Solution of Problem 2 (fxchg_pos)'); fprintf('\n'); fprintf('\n%12s','UB_Init_Capital'); for i=1:1:length(UB_Init_Capital) fprintf('%12.0f', UB_Init_Capital(i)); end fprintf('\n%5s','Objective '); for i=1:1:length(UB_Init_Capital) fprintf('%12.4f', Objectives(i)); end fprintf('\n%5s','Optimal points'); fprintf('\n%5s','Project'); for j=1:length(Points(:,1)) fprintf('\n%8s', project_name (j,:)); fprintf(' '); for i=1:1:length(UB_Init_Capital) fprintf('%12f', Points(j,i)); end end fprintf('\n'); fprintf('\n'); %Create plots for output subplot(2,1,2); plot1 = plot(UB_Init_Capital, Objectives, '-ob', 'LineWidth', 1.5, 'MarkerFaceColor', 'b', 'MarkerSize', 3); title('Objective vs Parameter: fxchg\_pos', 'FontSize', 12); xlabel('Parameter'); ylabel('Objectives'); grid on; %=======================================================================| %American Optimal Decisions, Inc. Copyright | %Copyright ©American Optimal Decisions, Inc. 2007-2014. | %American Optimal Decisions (AOD) retains copyrights to this material. | % | %Permission to reproduce this document and to prepare derivative works | %from this document for internal use is granted, provided the copyright | %and “No Warranty” statements are included with all reproductions | %and derivative works. | %For information regarding external or commercial use of copyrighted | %materials owned by AOD, contact AOD at support@aorda.com. | %=======================================================================|