Skip to content

Commit 0efa25d

Browse files
committed
Initialization of repo based on initial MatLab code base
0 parents  commit 0efa25d

7 files changed

Lines changed: 5232 additions & 0 deletions

File tree

Case study.xlsx

16.4 KB
Binary file not shown.

allpaths.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function p = allpaths(A,start,last)
2+
% find all direct paths from start to last
3+
% A is (n x 2) each row is an edges
4+
A = sortrows(A);
5+
b = true(size(A,1),1);
6+
p = gapengine(A,b,start,last);
7+
end
8+
function p = gapengine(A,b,start,last)
9+
% recursive engine
10+
if start==last
11+
p = {last};
12+
else
13+
bs = A(:,1) == start;
14+
next = A(bs & b,2);
15+
p = {};
16+
b(bs) = false;
17+
for k=1:length(next)
18+
i = next(k);
19+
pk = gapengine(A,b,i,last);
20+
pk = cellfun(@(p) [start, p], pk, 'unif', 0);
21+
p = [p, pk];
22+
end
23+
end
24+
end

cost_cdfdist.m

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
function pd1 = cost_cdfdist(c1,c2)
2+
3+
% Force all inputs to be column vectors
4+
c1 = c1(:);
5+
c2 = c2(:);
6+
7+
% Prepare figure
8+
clf;
9+
hold on;
10+
LegHandles = []; LegText = {};
11+
12+
13+
% --- Plot data originally in dataset "c1 data"
14+
% This dataset does not appear on the plot
15+
16+
% Get data limits to determine plotting range
17+
XLim = [0.8*min(c1),1.2*max(c1)];
18+
19+
% Create grid where function will be computed
20+
XLim = XLim + [0 1] * 0.01 * diff(XLim);
21+
XGrid = linspace(XLim(1),XLim(2),100);
22+
23+
24+
% --- Create fit "fit 1"
25+
pd1 = fitdist(c1,'kernel','kernel','normal','support','unbounded');
26+
YPlot1 = cdf(pd1,XGrid);
27+
hLine = plot(XGrid,YPlot1,'Color',[0 0 0],...
28+
'LineStyle','-', 'LineWidth',2,...
29+
'Marker','none', 'MarkerSize',6);
30+
LegHandles(end+1) = hLine;
31+
LegText{end+1} = 'Tentative cost CDF';
32+
33+
hold on
34+
35+
36+
a=find(YPlot1>0.999);
37+
if length(a)>0
38+
a=a(1);
39+
text(XGrid(a),0.96,1,strcat('cost=',num2str(round(XGrid(a)))),'Color','red','FontSize',14);
40+
41+
plot(XGrid(a),1,'o','MarkerSize',10,'LineWidth',2);
42+
end
43+
44+
hold on
45+
46+
% --- Plot data originally in dataset "c2 data"
47+
% This dataset does not appear on the plot
48+
49+
% Get data limits to determine plotting range
50+
XLim = [0.8*min(c2), 1.2*max(c2)];
51+
52+
% Create grid where function will be computed
53+
XLim = XLim + [0 1] * 0.01 * diff(XLim);
54+
XGrid = linspace(XLim(1),XLim(2),100);
55+
56+
xlabel('cost (Euros)','FontSize',20)
57+
ylabel('Cumulative probability','FontSize',20)
58+
bx = gca;
59+
bx.FontSize = 20;
60+
61+
% --- Create fit "fit 2"
62+
pd2 = fitdist(c2,'kernel','kernel','normal','support','unbounded');
63+
YPlot2 = cdf(pd2,XGrid);
64+
hLine = plot(XGrid,YPlot2,'Color',[0.7 0.7 0.7],...
65+
'LineStyle','-', 'LineWidth',2,...
66+
'Marker','none', 'MarkerSize',6);
67+
LegHandles(end+1) = hLine;
68+
LegText{end+1} = 'Permanent cost CDF';
69+
% Adjust figure
70+
box on;
71+
grid on;
72+
hold off;
73+
74+
% Create legend from accumulated handles and labels
75+
hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'FontSize', 18, 'Location', 'northwest');
76+
set(hLegend,'Interpreter','none');

cost_pdfdist.m

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
function pd1 = cost_pdfdist(c1,c2)
2+
3+
% Force all inputs to be column vectors
4+
c1 = c1(:);
5+
c2 = c2(:);
6+
7+
% Prepare figure
8+
clf;
9+
hold on;
10+
LegHandles = []; LegText = {};
11+
12+
%%
13+
% Get data limits to determine plotting range
14+
XLim = [0.8*min(c1),1.2*max(c1)];
15+
16+
% Create grid where function will be computed
17+
XLim = XLim + [0 1] * 0.01 * diff(XLim);
18+
XGrid = linspace(XLim(1),XLim(2),100);
19+
20+
%%
21+
% --- Plot data originally in dataset "c1 data"
22+
[CdfF,CdfX] = ecdf(c1,'Function','cdf'); % compute empirical cdf
23+
BinInfo.rule = 1;
24+
[~,BinEdge] = internal.stats.histbins(c1,[],[],BinInfo,CdfF,CdfX);
25+
[BinHeight,BinCenter] = ecdfhist(CdfF,CdfX,'edges',BinEdge);
26+
hLine = bar(BinCenter,BinHeight,'hist');
27+
set(hLine,'FaceColor','none','EdgeColor',[0 0 0],...
28+
'LineStyle','-', 'LineWidth',1);
29+
30+
LegHandles(end+1) = hLine;
31+
LegText{end+1} = 'Tentative cost histogram';
32+
33+
hold on
34+
35+
%%
36+
% --- Create fit "pdf1"
37+
pd1 = fitdist(c1,'kernel','kernel','normal','support','unbounded');
38+
YPlot = pdf(pd1,XGrid);
39+
hLine = plot(XGrid,YPlot,'Color',[0 0 0],...
40+
'LineStyle','-', 'LineWidth',3,...
41+
'Marker','none', 'MarkerSize',6);
42+
LegHandles(end+1) = hLine;
43+
LegText{end+1} = 'Tentative cost PDF';
44+
45+
hold on
46+
47+
%%
48+
% Get data limits to determine plotting range
49+
XLim = [0.8*min(c2), 1.2*max(c2)];
50+
51+
% Create grid where function will be computed
52+
XLim = XLim + [0 1] * 0.01 * diff(XLim);
53+
XGrid = linspace(XLim(1),XLim(2),100);
54+
%%
55+
% --- Plot data originally in dataset "c2 data"
56+
[CdfF,CdfX] = ecdf(c2,'Function','cdf'); % compute empirical cdf
57+
BinInfo.rule = 1;
58+
[~,BinEdge] = internal.stats.histbins(c2,[],[],BinInfo,CdfF,CdfX);
59+
[BinHeight,BinCenter] = ecdfhist(CdfF,CdfX,'edges',BinEdge);
60+
hLine = bar(BinCenter,BinHeight,'hist');
61+
set(hLine,'FaceColor','none','EdgeColor',[0.7 0.7 0.7],...
62+
'LineStyle','-', 'LineWidth',1);
63+
xlabel('cost (Euros)','FontSize',20)
64+
ylabel('PDF','FontSize',20)
65+
LegHandles(end+1) = hLine;
66+
LegText{end+1} = 'Permanent cost histogram';
67+
bx = gca;
68+
bx.FontSize = 20;
69+
70+
hold on
71+
72+
%%
73+
% --- Create fit "pdf2"
74+
75+
pd2 = fitdist(c2,'kernel','kernel','normal','support','unbounded');
76+
77+
YPlot = pdf(pd2,XGrid);
78+
hLine = plot(XGrid,YPlot,'Color',[0.7 0.7 0.7],...
79+
'LineStyle','-', 'LineWidth',2,...
80+
'Marker','none', 'MarkerSize',6);
81+
LegHandles(end+1) = hLine;
82+
LegText{end+1} = 'Permanent cost PDF';
83+
84+
% Adjust figure
85+
box on;
86+
hold off;
87+
88+
% Create legend from accumulated handles and labels
89+
hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'FontSize', 20, 'Location', 'northeast');
90+
set(hLegend,'Interpreter','none');

fitting.m

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
function fitting(y_opt,y_all,y_0,y_0_nouncertainty,T_pl)
2+
rng('default'); % for reproducibility
3+
4+
% Force all inputs to be column vectors
5+
y_opt = y_opt(:);
6+
y_all = y_all(:);
7+
y_0 = y_0(:);
8+
y_0_nouncertainty=y_0_nouncertainty(:)+1;
9+
10+
% Prepare figure
11+
clf;
12+
hold on;
13+
LegHandles = []; LegText = {};
14+
15+
%Data boundaries adjustment
16+
[CdfY,CdfX] = ecdf(y_all,'Function','cdf'); % compute empirical function
17+
a=CdfX(1)-2;
18+
b=CdfY(1);
19+
[CdfY,CdfX] = ecdf(y_0,'Function','cdf'); % compute empirical function
20+
c=CdfX(end)+2;
21+
d=CdfY(end);
22+
23+
24+
%%
25+
% --- Plot data originally in dataset "y_0_nouncertainty data"
26+
[CdfY,CdfX] = ecdf(y_0_nouncertainty,'Function','cdf'); % compute empirical function
27+
28+
CdfX=[a;CdfX;c];
29+
CdfY=[b;CdfY;d];
30+
31+
hLine = plot(CdfX,CdfY,'lineWidth',2,'Color' , [0.7 0.7 0.7],'DisplayName','Orig Dur');
32+
33+
hold on;
34+
35+
%%
36+
% --- Plot data originally in dataset "y_0 data"
37+
[CdfY,CdfX] = ecdf(y_0,'Function','cdf'); % compute empirical function
38+
%hLine = stairs(CdfX,CdfY,'Color',[0 0 0],'LineStyle','-', 'LineWidth',1);
39+
%hold on;
40+
41+
% --- Create fit for "y_0 data"
42+
CdfX(1)=CdfX(1)-1;
43+
CdfX=[a;CdfX;c];
44+
CdfY=[b;CdfY;d];
45+
x=CdfX;
46+
xq2 = linspace(CdfX(1),CdfX(end),200);
47+
p1 = pchip(x,CdfY,xq2);
48+
plot(xq2,p1,':','lineWidth',2,'Color' , [0.7 0.7 0.7],'DisplayName','NoMit')
49+
hold on
50+
51+
%%
52+
% --- Plot data originally in dataset "y_all data"
53+
[CdfY,CdfX] = ecdf(y_all,'Function','cdf'); % compute empirical function
54+
%hLine = stairs(CdfX,CdfY,'Color',[0.333333 0.666667 0],'LineStyle','-', 'LineWidth',1);
55+
56+
% --- Create fit for "y_all data"
57+
CdfX(1)=CdfX(1)-1;
58+
CdfX=[a;CdfX;c];
59+
CdfY=[b;CdfY;d];
60+
61+
x=CdfX;
62+
xq2 = linspace(CdfX(1),CdfX(end),200);
63+
p2 = pchip(x,CdfY,xq2);
64+
plot(xq2,p2,'--','lineWidth',2, 'Color' , [0.7 0.7 0.7],'DisplayName','Permanent')
65+
hold on;
66+
67+
%%
68+
% --- Plot data originally in dataset "y_opt data"
69+
[CdfY,CdfX] = ecdf(y_opt,'Function','cdf'); % compute empirical function
70+
%hLine = stairs(CdfX,CdfY,'Color',[0.333333 0 0.666667],'LineStyle','-', 'LineWidth',1);
71+
72+
% --- Create fit for "y_opt data"
73+
CdfX(1)=CdfX(1)-1;
74+
CdfX=[a;CdfX;c];
75+
CdfY=[b;CdfY;d];
76+
x=CdfX;
77+
xq2 = linspace(CdfX(1),CdfX(end),200);
78+
p3 = pchip(x,CdfY,xq2);
79+
plot(xq2,p3,'lineWidth',2,'Color' , 'k','DisplayName','Tentative')
80+
81+
hold on;
82+
83+
a=find(x>=T_pl);
84+
if length(a)>0
85+
a=a(1);
86+
text(T_pl,CdfY(a)-0.05,1,strcat('Target duration=',num2str(T_pl)),'Color','red','FontSize',14);
87+
plot(T_pl+1,CdfY(a)+0.006,'o','Color','red','MarkerSize',10,'LineWidth',2,'DisplayName','Planned duration');
88+
end
89+
%%
90+
% Create grid where function will be computed
91+
XLim = get(gca,'XLim');
92+
XLim = XLim + [-1 1] * 0.01 * diff(XLim);
93+
XGrid = linspace(XLim(1),XLim(2),800);
94+
xlabel('Duration (days)','FontSize',20)
95+
ylabel('Cumulative probability','FontSize',20)
96+
bx = gca;
97+
bx.FontSize = 20;
98+
99+
% Adjust figure
100+
box on;
101+
hold off;
102+
103+
% Create legend from accumulated handles and labels
104+
legend('Orig Dur','No Mit','Permanent','Tentative');
105+
hLegend = legend(LegHandles,LegText,'Orientation', 'vertical', 'FontSize', 18, 'Location', 'northeast');
106+
set(hLegend,'Interpreter','none');
107+
108+
109+
grid on

0 commit comments

Comments
 (0)