:- lib(ic).
:- lib(eplex).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
main :-
ST is 3, % ms
L_MS is 6 / 1000, % ms
N_MS is 44, % minislots
DN is L_MS * N_MS, % ms
FC is ST + DN, % ms
write(" FC: "), writeln(FC),
T_List = [5, 8, 16, 18, 13, 12, 15, 8, 16, 6],
W_List = [5, 10, 8, 9, 9, 9, 10, 7, 5, 7],
F_List = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
% all lists needs to have the same length
length(T_List, N),
length(J_List, N),
length(W_List, N),
length(W_List, N),
% Message Under Analysis
T_Mua is 14, % ms
W_Mua is 12, % minislots
F_Mua is 11, % priority
Min_Load is N_MS + 2 - (F_Mua + W_Mua),
Max_Load is N_MS,
write("Min_Load: "), writeln(Min_Load),
write("Max_Load: "), writeln(Max_Load),
eplex: eplex_solver_setup(min(0)),
(count(L, 1, 999), param(N, FC, T_List, W_List, F_List, Max_Load, Min_Load) do
once complete_search(L, N, FC, T_List, W_List, F_List, Max_Load, Min_Load, BoolMatrix, LoadMatrix),
eplex: eplex_solve(_),
% Print the results
write("Solution L = "), writeln(L),
(count(Cycle, 1, L), param(N, BoolMatrix, LoadMatrix) do
Row_1 is subscript(BoolMatrix, [Cycle, 1 .. N]),
Row_2 is subscript(LoadMatrix, [Cycle, 1 .. N]),
eplex: (Load $= sum(Row_2)),
write(Row_1), write(" :: "), writeln(Load)
),
writeln("-------------------------------")
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
complete_search(L, N, FC, T_List, W_List, F_List, Max_Load, Min_Load, BoolMatrix, LoadMatrix) :-
% Generate the Optimization Variables Matrix
dim(BoolMatrix, [L, N]),
(count(Cycle, 1, L), param(L, N, BoolMatrix) do
Row is subscript(BoolMatrix, [Cycle, 1 .. N]),
eplex: (Row :: [0 .. 1]),
Cycle #=< L - 6,
eplex: (integers(Row))
;
true
),
%Th is 8,
%int_csp(L, Th, N, BoolMatrix),
% Constraints regarding the total number of instances per message over a period of time
(count(Cycle, 1, L), param(FC, T_List, N, BoolMatrix) do
(count(Message, 1, N),
foreach(T, T_List), param(FC, Cycle, BoolMatrix) do
Tmp is ceiling(Cycle * FC / T),
MaxNrOfInstances is fix(Tmp),
Col is subscript(BoolMatrix, [1 .. Cycle, Message]),
eplex: (sum(Col) $=< MaxNrOfInstances)
%write(MaxNrOfInstances), write(" ")
)
%writeln("")
),
%writeln("-------------------------------"),
% Generate the Load Matrix
dim(LoadMatrix, [L, N]),
(count(Cycle, 1, L), param(W_List, N, BoolMatrix, LoadMatrix) do
(count(Message, 1, N),
foreach(W, W_List), param(Cycle, BoolMatrix, LoadMatrix) do
eplex: (LoadMatrix[Cycle, Message] $= BoolMatrix[Cycle, Message] * (W - 1))
)
),
% Constraints regarding the load of the cycles
load_of_cycles(L, N, W_List, F_List, Max_Load, Min_Load, N, LoadMatrix).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load_of_cycles(L, N, W_List, F_List, Max_Load, Min_Load, N, LoadMatrix) :-
(count(Cycle, 1, L), param(W_List, F_List, Max_Load, Min_Load, N, LoadMatrix) do
(count(Message, 1, N),
foreach(F, F_List),
foreach(W, W_List),
param(Max_Load, Cycle, LoadMatrix) do
Row is subscript(LoadMatrix, [Cycle, 1 .. Message - 1]),
eplex: (F + W - 1 + sum(Row) $=< Max_Load)
),
Row is subscript(LoadMatrix, [Cycle, 1 .. N]),
eplex: (sum(Row) $>= Min_Load)
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
int_csp(L, Th, N, BoolMatrix) :-
L < Th,
(count(Cycle, 1, L), param(N, BoolMatrix) do
Row is subscript(BoolMatrix, [Cycle, 1 .. N]),
eplex: (integers(Row))
).
int_csp(L, Th, N, BoolMatrix) :-
L >= Th,
(count(Cycle, 1, Th), param(N, BoolMatrix) do
Row is subscript(BoolMatrix, [Cycle, 1 .. N]),
eplex: (integers(Row))
).