diff --git a/mdocean/optimization/gradient_optim.m b/mdocean/optimization/gradient_optim.m index 8fe5bfd..8334b1d 100644 --- a/mdocean/optimization/gradient_optim.m +++ b/mdocean/optimization/gradient_optim.m @@ -118,9 +118,17 @@ probs{i} = problem; tol = eps(2); - if any(abs(X_opt_raw(b.mins_flexible) - b.X_mins(b.mins_flexible)) < tol) ... - || any(abs(X_opt_raw(b.maxs_flexible) - b.X_maxs(b.maxs_flexible)) < tol) - warning('Optimization is up against a flexible variable bound, consider changing bounds') + min_active = abs(X_opt_raw - b.X_mins) < tol; + max_active = abs(X_opt_raw - b.X_maxs) < tol; + flexible_min_active = b.mins_flexible & min_active; + flexible_max_active = b.maxs_flexible & max_active; + if any(flexible_min_active) || any(flexible_max_active) + var_opt = b.var_names(1:end-1); + max_string = strcat(var_opt(flexible_max_active)," "); + min_string = strcat(var_opt(flexible_min_active)," "); + msg = ['Optimization is up against a flexible variable bound, consider changing bounds. ',... + 'At max: ' horzcat(max_string{:}) ', at min: ' horzcat(min_string{:})]; + warning(msg) end X_opt = [X_opt_raw; evaluate(X(end),struct())]; % add material back onto design vector diff --git a/mdocean/optimization/multiobjective/pareto_search.m b/mdocean/optimization/multiobjective/pareto_search.m index 725cfc7..5abbc23 100644 --- a/mdocean/optimization/multiobjective/pareto_search.m +++ b/mdocean/optimization/multiobjective/pareto_search.m @@ -84,12 +84,30 @@ 'ParetoSetChangeTolerance',1.6e-8,'MaxIterations',100); if ~isempty(X0) probMO.options.InitialPoints = X0_struct; + else + probMO.x0 = []; + warning('All starting points are infeasible') end probMO.solver = 'paretosearch'; probMO.nvars = num_DVs; %% Execute pareto search disp('Finished finding pareto seed points. Now starting paretosearch.') - [x,fval,flag,output,residuals] = paretosearch(probMO); + try + [x,fval,flag,output,residuals] = paretosearch(probMO); + catch ME + if (strcmp(ME.identifier,'MATLAB:emptyObjectDotAssignment')) + msg = ['Pareto search could not find any feasible starting points, ' ... + 'so plot errored. Retrying without plot.']; + warning(msg) + probMO.options.PlotFcn = []; + [x,fval,flag,output,residuals] = paretosearch(probMO); + if flag==-2 + error(output.message) + end + else + rethrow(ME) + end + end %% Process and save results utopia = min(fval); diff --git a/mdocean/optimization/sensitivities/param_sweep.m b/mdocean/optimization/sensitivities/param_sweep.m index 6802d4a..73f6c85 100644 --- a/mdocean/optimization/sensitivities/param_sweep.m +++ b/mdocean/optimization/sensitivities/param_sweep.m @@ -103,6 +103,13 @@ slope_LCOE = get_slope(LCOE, ratios, LCOE_nom); slope_Pvar = get_slope(P_var, ratios, Pvar_nom); +if all(~isfinite(slope_LCOE),'all') || all(~isfinite(slope_Pvar),'all') + msg = ['All slopes are NaN, meaning all optimizations failed. ' ... + 'This might be because no feasible solution can be found. ' ... + 'slope_LCOE = ', num2str(slope_LCOE), ' and slope_Pvar = ', num2str(slope_Pvar)]; + error(msg) +end + [~,LCOE_sort_idx] = sort(abs(slope_LCOE),'MissingPlacement','first'); [~,Pvar_sort_idx] = sort(abs(slope_Pvar),'MissingPlacement','first');