Hello,
I modified to code, and got it to work but I still have one issue to solve. Here's the updated version :
### 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];
Now, given a dataset as following :
### 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;
Using the quadratic function, or Taylor's expansion, the solver gives me the following output, which is also confirmed to be right from math :
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
;
However, for my tutor, using quadratic function is not acceptable cause the solver could produce an output different from what I'm expecting, and using Taylor's serie is not good for the learning purpose.
I got asked to linearize the absolute value, and I proceeded as you can see in my ".mod" file (I added 2 constraints "l1" and "l2" and changed the objective function).
I runned the code but the result is bit different from the one obtained with the first 2 methods :
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
;
I can't figure out the mismatching in the results since the linearization should be right.
Can you help me? what am I doing wrong?
Thanks in advice