Skip to content

Instantly share code, notes, and snippets.

@AndreFCruz
Created January 8, 2018 14:27
Show Gist options
  • Select an option

  • Save AndreFCruz/cbcf8566da03eac2f8241cbd4bac6125 to your computer and use it in GitHub Desktop.

Select an option

Save AndreFCruz/cbcf8566da03eac2f8241cbd4bac6125 to your computer and use it in GitHub Desktop.
Constraint logic programming exercise.
:- use_module(library(lists)).
:- use_module(library(clpfd)).
%% P13 - Prova modelo algures no grupo do fb
% attend(+, -, -)
attend(FilmList, Goings, Worth) :-
length(FilmList, N),
length(Goings, N),
domain(Goings, 0, 1),
length(Tasks, N),
generateTasks(FilmList, Goings, Tasks),
Machines = [machine(1, 1), machine(0, 1000)],
cumulatives(Tasks, Machines, [bound(upper)]),
getWorthsList(FilmList, WorthsList),
scalar_product(WorthsList, Goings, #=, Worth),
append(Goings, [Worth], Vars),
labeling([maximize(Worth)], Vars).
generateTasks([], [], []).
generateTasks([(S,D,_) | Films], [G | Goings], [task(S, D, _, G, 1) | Tasks]) :-
generateTasks(Films, Goings, Tasks).
getWorthsList([], []).
getWorthsList([(_,_,Worth) | Films], [Worth | WorthsList]) :-
getWorthsList(Films, WorthsList).
% attend([(1,3,2), (1,4,4), (4,4,3)], Goings, Worth).
% attend([(1,3,2), (1,4,4), (4,4,1)], Goings, Worth).
% attend([(1,3,3), (1,4,4), (3,5,5), (4,1,1), (4,4,3), (5,4,3), (6,3,1), (8,3,3)], Goings, Worth).
@AndreFCruz
Copy link
Author

p13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment