On a set {1,….,N} is defined a discrete cumulative distribution function :
F(i)=yi, i=1,...,N,
With
F(i) ≥ F(i − 1) ∀i = 2,...,N.Define an other discrete cumulative distribution function G, which approximates F.
G shall assume n<N values (distinct possibles values of G(i) r n), and shall be defined in a way in which the absolute error (the sum of the differences |F(i) - G(i)|) is as low as possible.
Formulate the AMPL model for this problem and solve it with some random data.
### SET
set N := 1..8 ;set n := 1..5 ;
### PARAMETERS
param ncount := 5;param Ncount := 16;
param val :=1 0.22 0.33 0.54 0.65 0.76 0.87 0.88 1 ;
### SETS
set N ;set n ;
### PARAMS
param val{N} <= 1, >= 0;param ncount;param Ncount;param mult := Ncount/ncount integer;param k default 1;
param x2 {i in 1..ncount} = floor (i*mult);
### VARS
var x{n} <= 1, >= 0 ;
### CONSTR
subject to range1{l in N : l>1} : val[l] >= val[l-1];
subject to range2{j in n : j <= mult*k } : x[j] = x[j+1];
subject to max_val1 : x[ncount] = 1 ;subject to max_val2 : val[Ncount] = 1 ;
### OBJ
minimize total_cost : sum{i in N , j in n}abs(val[i] - x[j]);
--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+unsubscribe@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.
### SETS
param n;
param N;
set Nset:=1..N;
set nset:=1..(n-1);
### PARAMS
param F{Nset} <= 1, >= 0;
param mult := (N-1)/(n-1);
param z := N;
### VARS
var G{Nset} <= 1, >= 0;
var t{Nset} <= 1 >= 0;
### CONSTR
###subject to range{d in nset}: G[ceil(mult*d)] <= F[ceil(mult*d)];
subject to range2{e in nset: e > 1}: G[ceil(mult*(e))] >= F[ceil(mult*(e-1))];
subject to range3{f in nset} : G[ceil(mult*f)] - G[ceil(mult*(f-1)) + 1] = 0;
subject to range4{g in Nset: g < z} : G[g] <= G[g+1];
subject to max_val : G[N] = 1 ;
subject to l1{h in Nset} : t[h] >= (F[h] - G[h]);
subject to l2{l in Nset} : t[l] >= -(F[l] - G[l]);
### OBJ
###minimize total_cost : sum{i in Nset}(F[i] - G[i])^2; quadratic formula
###minimize total_cost : sum{i in Nset}(1 + ((0.5)*(((F[i] - G[i])^2) - 1))); taylor's serie
minimize total_cost : sum{i in Nset}t[i];
### PARAMETERS
param n := 4;
param N := 10;
param F :=
1 0.1
2 0.3
3 0.4
4 0.45
5 0.55
6 0.6
7 0.8
8 0.85
9 0.95
10 1;
G [*] :=
1 0.266667
2 0.266667
3 0.266667
4 0.533333
5 0.533333
6 0.533333
7 0.866667
8 0.866667
9 0.866667
10 1
;
G [*] :=
1 0.3
2 0.3
3 0.3
4 0.55
5 0.55
6 0.55
7 0.85
8 0.85
9 0.85
10 1
;