LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
example_infer_mle_open.m
1clear node jobclass solver AvgTable
2%% Example: MLE estimation on an open network
3% Copyright (c) 2012-2026, Imperial College London
4% All rights reserved.
5
6%% define model
7model = Network('model');
8
9node{1} = Delay(model, 'Delay');
10node{2} = Queue(model, 'Queue1', SchedStrategy.FCFS);
11node{3} = Source(model, 'Source');
12node{4} = Sink(model, 'Sink');
13
14jobclass{1} = OpenClass(model, 'Class1', 0);
15jobclass{2} = OpenClass(model, 'Class2', 0);
16
17node{1}.setService(jobclass{1}, Exp.fitMean(1.0));
18node{1}.setService(jobclass{2}, Exp.fitMean(1.0));
19node{2}.setService(jobclass{1}, Exp(NaN)); % NaN = to be estimated (true demand = 0.1)
20node{2}.setService(jobclass{2}, Exp(NaN)); % NaN = to be estimated (true demand = 0.3)
21node{3}.setArrival(jobclass{1}, Exp(1.0)); % arrival rate = 1.0
22node{3}.setArrival(jobclass{2}, Exp(0.5)); % arrival rate = 0.5
23
24P = model.initRoutingMatrix;
25P{1,1} = [0,1,0,0; 0,0,0,1; 1,0,0,0; 0,0,0,0];
26P{2,2} = [0,1,0,0; 0,0,0,1; 1,0,0,0; 0,0,0,0];
27model.link(P);
28
29%% Generate synthetic dataset consistent with model
30% True demands D1=0.1, D2=0.3, arrival rates lambda1=1.0, lambda2=0.5
31% True utilization U = lambda1*D1 + lambda2*D2 = 0.1 + 0.15 = 0.25
32% True response times R1 = D1/(1-U) = 0.133, R2 = D2/(1-U) = 0.4
33n = 100;
34ts = 1:n;
35arvr1_samples = 1.0*ones(n,1) + randn(n,1)*0.05;
36arvr2_samples = 0.5*ones(n,1) + randn(n,1)*0.03;
37util_samples = 0.25*ones(n,1) + randn(n,1)*0.02;
38util_samples = max(0.01, min(0.95, util_samples));
39respt1_samples = 0.1./(1 - util_samples);
40respt2_samples = 0.3./(1 - util_samples);
41
42%% Create SampledMetric objects
43lambda1 = SampledMetric(MetricType.ArvR, ts, arvr1_samples, node{2}, jobclass{1});
44lambda2 = SampledMetric(MetricType.ArvR, ts, arvr2_samples, node{2}, jobclass{2});
45respT1 = SampledMetric(MetricType.RespT, ts, respt1_samples, node{2}, jobclass{1});
46respT2 = SampledMetric(MetricType.RespT, ts, respt2_samples, node{2}, jobclass{2});
47util = SampledMetric(MetricType.Util, ts, util_samples, node{2});
48
49%% Estimate with MLE
50fprintf(1, '\n=== MLE Estimator (Open Network) ===\n');
51options = ParamEstimator.defaultOptions;
52options.method = 'mle';
53se = ParamEstimator(model, options);
54se.addSamples(lambda1);
55se.addSamples(lambda2);
56se.addSamples(respT1);
57se.addSamples(respT2);
58se.addSamples(util);
59se.interpolate();
60estVal = se.estimateAt(node{2});
61fprintf(1, 'MLE demands: Class1=%.4f (true=0.1000), Class2=%.4f (true=0.3000)\n', estVal(1), estVal(2));
62
63%% Solve model
64solver{1} = SolverMVA(model);
65fprintf(1, '\nSOLVER: %s\n', solver{1}.getName());
66AvgTable{1} = solver{1}.getAvgTable();
67AvgTable{1}