Sir or Ma'am,
I am having issues calling some of the functions within matlab and Simulink using the AMPL API.
The code I am writing is done in simulink, So I had to wrap a API code in an S function. When this is done there are a few issues that arise.
The first is some of the code is erroring out, more specifically the DataFrame and ampl.expand give me errors when run.
The Error is: No method 'expand' with matching signature found for class 'com.ampl.AMPL'.
While same type of error happens for Data frame.
Another error is that the API seems to randomly drop connection to ampl when solving some simple problems with relaxation of constraints resulting in no call to cplex.
Dose this make since? Is there something that I should explain more on?
Code that is giving the errors.
S-function output block.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Output(block)
% ==============================================
% Java Part
%Import Java
import java.lang.Object;
import com.ampl.*;
% import com.ampl.Entity;
% import com.ampl.Parameter;
% import com.ampl.Set;
% import com.ampl.Variable;
% import com.ampl.Constraint;
% import com.ampl.Objective;
% Look at msfcn_times_two_JAVA example from mathworks
% End Java part
% ===============================================
global MOC T_sp_pre Y_pre Const DiscParam debug_var ub lb NumZone
global k k_start Des_Temp P P_dT DBT HoursForIdent stepsPerHour
%% AMPL Setup
%var preload var
AMPL_folder = '\AMPL\';
% Create an AMPL instance
ampl = AMPL();
% Load from file the ampl model
ampl.read([pwd AMPL_folder 'AMPL_' num2str(NumZone) 'Zone_model.mod']);
ampl.readData([pwd AMPL_folder 'AMPL_data.dat']);
ampl.setOption('solver', 'CPLEX');
ampl.setOption('cplex_options',...
'presolve 1 resolve 1 timelimit=900');
ObjFunc = ampl.getObjective('ObjFunc');
ampl.expand(ObjFunc);
fprintf('New objective value: %f\n', ObjFunc.value());
Y_pre_ampl = ampl.getParameter('Y_pre');
df = DataFrame(1,1:NumZone);
for i=1:NumZone
df.setColumn(i,Y_pre(:,i));
end
Y_pre_ampl.setData(df);
ampl.close();
%endfunction
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Respectfully,
Maxwell T Harris
Colorado School of Mines - (BS) Engineering with a Specialty in Mechanics - December 2012
Colorado School of Mines - (MS) Mechanical Engineering - Expected 2016