-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathhorario_medico_CP.pi
94 lines (80 loc) · 2.67 KB
/
horario_medico_CP.pi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import cp.
%main => modelo .
main ?=> modelo.
main => printf("\n No solutions are found !!!\n").
%%% MUITAS SOLUCOES AQUI
%main =>
% L = findall(_, $modelo),
% writef("\n Total de solucoes: %d \n", length(L)) .
modelo =>
Dias = 5, % segunda = 1, ...., sexta-feira = 5
Consultorio = 4,
% to print names and code
L_dom = [ oftalmo, otorrino, pediatra, gineco,
% 1 2 3 4
cardio, dermato, clin_geral ],
% 5 6 7
Quadro = new_array(Consultorio, Dias ), %% Lin x Col
Quadro :: 1 .. L_dom.len , %% operador len . "eh colado"
%% O medico 2 NUNCA trabalha no consultorio 1
foreach ( J in 1 .. Dias )
Quadro[1,J] #!= 2
end,
%% O medico 5 NUNCA trabalha no consultorio 4
foreach ( J in 1 .. Dias )
Quadro[4,J] #!= 5
end,
% O medico 6 soh vem na 2a (1) e 6a. (5) feira
count( 6, [Quadro[I,1] : I in 1 .. Consultorio],1),
count( 6, [Quadro[I,5] : I in 1 .. Consultorio],1),
%% O Clin Geral trabalha 2a, 4as e 6as.
foreach ( J in {1,3,5} )
count(7,[Quadro[I,J] : I in 1 .. Consultorio],1)
end,
%sum([ Quadro[I,J] : I in 1 .. Consultorio, J in 1..Dias , Quadro[I,J] ==7 ]) #= 2,
%% Ninguém trabalha no mesmo consultorio em dias seguidos
foreach ( J in 1 .. Dias )
all_different( [Quadro[I,J] : I in 1..Consultorio] )
end,
%% Ninguém trabalha no mesmo dia em mais de um consultorio
foreach ( I in 1 .. Consultorio )
all_different( [Quadro[I,J] : J in 1..Dias] )
end,
% A BUSCA
solve([ff], Quadro),
% UMA SAIDA
printf("\n Uma escolha:"),
print_matrix( Quadro ),
print_matrix_NAMES( Quadro , L_dom ),
printf("....................................\n")
.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
print_matrix( M ) =>
L = M.length,
C = M[1].length,
nl,
foreach(I in 1 .. L)
foreach(J in 1 .. C)
printf("%w " , M[I,J] )
%printf("%w " , print_n_lista( M[I,J], L) )
%% printf("(%d,%d): %w " , I, J, M[I,J] ) -- FINE
end,
nl
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
print_matrix_NAMES( M, Lista ) =>
L = M.length,
C = M[1].length,
nl,
foreach(I in 1 .. L)
foreach(J in 1 .. C)
printf(":%w \t" , print_n_lista( M[I,J], Lista) )
% printf("(%d,%d): %w " , I, J, M[I,J] ) -- FINE
end,
nl
end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
print_n_lista( _, [] ) = [].
print_n_lista( 1, [A|_] ) = A.
print_n_lista( N, [_|B] ) = print_n_lista( (N-1), B ) .
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%