Trabajo Final
Trabajo Final
Trabajo Final
Para comparar los resultados de la simulación, se graficarán los datos de todas las ciudades en dos
gráficas: una para los tiempos de entrega y otra para los metros recorridos.
UIFigure matlab.ui.Figure
StartSimulationButton matlab.ui.control.Button
UIAxes1 matlab.ui.control.UIAxes
UIAxes2 matlab.ui.control.UIAxes
AlertsTextAreaLabel matlab.ui.control.Label
AlertsTextArea matlab.ui.control.TextArea
ResultsTextAreaLabel matlab.ui.control.Label
ResultsTextArea matlab.ui.control.TextArea
end
% Data properties
times
distances
stopTimes
end
function simulateDeliveries(app)
app.times = containers.Map();
app.distances = containers.Map();
app.stopTimes = containers.Map();
for i = 1:length(app.cities)
city = app.cities{i};
end
end
function monitorStopTimes(app)
alerts = '';
for i = 1:length(app.cities)
city = app.cities{i};
stopTimes = app.stopTimes(city);
for j = 1:length(stopTimes)
stopTime = stopTimes(j);
alerts = sprintf('%s%s Delivery %d: Stop time %.2f min. Send message to driver.\n', alerts,
city, j, stopTime);
alerts = sprintf('%s%s Delivery %d: Stop time %.2f min. Call driver.\n', alerts, city, j,
stopTime);
alerts = sprintf('%s%s Delivery %d: Stop time %.2f min. Call police.\n', alerts, city, j,
stopTime);
end
end
end
app.AlertsTextArea.Value = alerts;
end
function plotResults(app)
cla(app.UIAxes1);
cla(app.UIAxes2);
hold(app.UIAxes1, 'on');
for i = 1:length(app.cities)
city = app.cities{i};
end
Facultad de Ingeniería
Programa: Ingeniería Industrial
Asignatura: Programación I
hold(app.UIAxes1, 'off');
legend(app.UIAxes1);
hold(app.UIAxes2, 'on');
for i = 1:length(app.cities)
city = app.cities{i};
end
hold(app.UIAxes2, 'off');
legend(app.UIAxes2);
end
function compareResults(app)
results = '';
for i = 1:length(app.cities)-1
cityCoastal = app.cities{i};
cityCapital = app.cities{end};
Facultad de Ingeniería
Programa: Ingeniería Industrial
Asignatura: Programación I
avgTimeCoastal = mean(app.times(cityCoastal));
avgTimeCapital = mean(app.times(cityCapital));
avgDistanceCoastal = mean(app.distances(cityCoastal));
avgDistanceCapital = mean(app.distances(cityCapital));
results = sprintf('%s Average Time: %.2f min vs %.2f min\n', results, avgTimeCoastal,
avgTimeCapital);
end
app.ResultsTextArea.Value = results;
end
end
app.simulateDeliveries();
app.monitorStopTimes();
app.plotResults();
app.compareResults();
Facultad de Ingeniería
Programa: Ingeniería Industrial
Asignatura: Programación I
end
end
% Component initialization
function createComponents(app)
% Create StartSimulationButton
app.StartSimulationButton.ButtonPushedFcn = createCallbackFcn(app,
@StartSimulationButtonPushed, true);
% Create UIAxes1
app.UIAxes1 = uiaxes(app.UIFigure);
title(app.UIAxes1, 'Title')
Facultad de Ingeniería
Programa: Ingeniería Industrial
Asignatura: Programación I
xlabel(app.UIAxes1, 'X')
ylabel(app.UIAxes1, 'Y')
% Create UIAxes2
app.UIAxes2 = uiaxes(app.UIFigure);
title(app.UIAxes2, 'Title')
xlabel(app.UIAxes2, 'X')
ylabel(app.UIAxes2, 'Y')
% Create AlertsTextAreaLabel
app.AlertsTextAreaLabel = uilabel(app.UIFigure);
app.AlertsTextAreaLabel.HorizontalAlignment = 'right';
app.AlertsTextAreaLabel.Text = 'Alerts';
% Create AlertsTextArea
app.AlertsTextArea = uitextarea(app.UIFigure);
% Create ResultsTextAreaLabel
app.ResultsTextAreaLabel = uilabel(app.UIFigure);
app.ResultsTextAreaLabel.HorizontalAlignment = 'right';
Facultad de Ingeniería
Programa: Ingeniería Industrial
Asignatura: Programación I
app.ResultsTextAreaLabel.Text = 'Results';
% Create ResultsTextArea
app.ResultsTextArea = uitextarea(app.UIFigure);
app.UIFigure.Visible = 'on';
end
end
% Construct app
createComponents(app)
registerApp(app, app.UIFigure)
Facultad de Ingeniería
Programa: Ingeniería Industrial
Asignatura: Programación I
if nargout == 0
clear app
end
end
function delete(app)
delete(app.UIFigure)
end
end
end