-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathclingo-dl.tex
146 lines (141 loc) · 4.71 KB
/
clingo-dl.tex
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
% ----------------------------------------------------------------------
\begin{frame}{\clingodl}
\begin{itemize}
\item \structure{Idea} \ extend \clingo\ with difference constraints over integers
\item \structure{Features} \
\begin{itemize}
\item integer variables not subject to grounding
\item a difference constraint \
`\(
{x-y}\leq c
\)'
\par
is represented as \
`\lstinline[mathescape]{&diff(x-y) <= c}'
\item yields canonical witnessing integer assignments
\end{itemize}
\item \structure{References} \ \cite{jakaosscscwa17a,karoscwa21a}
\item \structure{Applications} \ \cite{abjoossctowa21a,hamunescwa23a,rascwachliso23a}
\end{itemize}
\end{frame}
% ----------------------------------------------------------------------
%
% draw the task scheduling instance and put it in a box (the poor thing)
\newbox\instance%
\sbox\instance{%
\newcommand\tasks[1]{
\raisebox{-.5pt}{\begin{tikzpicture}[
define color/.code 2 args={\definecolor{##1}{HTML}{##2}},
start chain,node distance=0,
every node/.style={minimum height=2.5mm,minimum width=2.5mm,draw,inner sep=0,xshift=-0.4pt,on chain},
]
\draw
foreach \c/\n in {#1} {
{ [define color={ctemp}{\c}]
foreach \i in {1,...,\n} {
node [fill=ctemp] { }
}
}
}
;
\end{tikzpicture}
}}%
\begin{tabular}{cll}\toprule
& \multicolumn{2}{c}{durations}\\\cmidrule{2-3}
tasks & unit~\(u_1\) & unit~\(u_2\) \\\midrule
\(t_1\) & \tasks{edd400/3} & \tasks{c4a000/4} \\
\(t_2\) & \tasks{73d216/1} & \tasks{4e9a06/6} \\
\(t_3\) & \tasks{f57900/5} & \tasks{ce5c00/5} \\\bottomrule
\end{tabular}}
%
% ----------------------------------------------------------------------
\begin{frame}[fragile]{Example}{Task scheduling}
\begin{adjustbox}{max totalsize={\textwidth}{.83\textheight},keepaspectratio}
\begin{lstlisting}
% instance
bound(16). unit(1). unit(2).
task(1). dur(1,1,3). dur(1,2,4).
task(2). dur(2,1,1). dur(2,2,6).
task(3). dur(3,1,5). dur(3,2,5).
% encoding
{assign(S,T): task(S)}=1 :- task(T).
{assign(S,T): task(T)}=1 :- task(S).
&diff { (S,U)-(S+1,U) } <= -D :- assign(S,T), dur(T,U,D), task(S+1).
&diff { (S,U)-(S,U+1) } <= -D :- assign(S,T), dur(T,U,D), unit(U+1).
&diff { 0-(S,U) } <= 0 :- assign(S,T), unit(U).
&diff { (S,U)-0 } <= B-D :- assign(S,T), dur(T,U,D), bound(B).
\end{lstlisting}
\end{adjustbox}
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,xshift=-1em,yshift=-2.2cm] at (current page.north east){\usebox\instance};
\end{tikzpicture}
\end{frame}
% ----------------------------------------------------------------------
%
% draw a solution and put it in a box (the poor thing)
\newbox\solution%
\sbox{\solution}{%
\newcommand\arrow[3][0]{%
\draw[->] ($(#2.south)+(.5mm,0)$) |- ($(#2)!.5!(#3)+(0,#1)$) -| ($(#3.north)-(.5mm,0)$);}
\newcommand\solTasks[2]{%
\raisebox{-.5pt}{\begin{tikzpicture}[
remember picture,
define color/.code 2 args={\definecolor{##1}{HTML}{##2}},
start chain,node distance=0,
every node/.style={minimum height=2.5mm,minimum width=2.5mm,on chain,draw,fill=ctemp,inner sep=0,xshift=-0.4pt},
task/.style={},
gap/.style={opacity=0},
]
\draw
foreach \c/\s/\n[count=\g] in {#2} {
{ [define color={ctemp}{\c}]
foreach \i in {1,...,\n} {
node [\s] (#1-\g-\i) { }
}
}
}
;
\end{tikzpicture}
}}
\begin{tabular}{cl}\toprule
unit & \multicolumn{1}{c}{solution} \\\midrule
& \(t_2 < t_3 < t_1\) \\
\(u_1\) & \solTasks{s21}{73d216/task/1,f57900/task/5,edd400/task/3} \\[1mm]
\(u_2\) & \solTasks{s22}{000000/gap/1,4e9a06/task/6,ce5c00/task/5,c4a000/task/4} \\\bottomrule
\end{tabular}
\begin{tikzpicture}[overlay,remember picture]
\arrow{s21-1-1}{s22-2-1} \arrow{s21-2-5}{s22-3-1} \arrow{s21-3-3}{s22-4-1}
\end{tikzpicture}\hfill
}
% ----------------------------------------------------------------------
\begin{frame}[fragile]{Example}{Task scheduling}
\begin{adjustbox}{max totalsize={\textwidth}{.83\textheight},keepaspectratio}
\begin{lstlisting}
$ clingo-dl version 1.4.0
Reading from example.lp
Solving...
Answer: 1
bound(16) unit(1) unit(2)
task(1) task(2) task(3)
dur(1,1,3) dur(1,2,4) dur(2,1,1)
dur(2,2,6) dur(3,1,5) dur(3,2,5)
assign(1,2) dl((1,1),0) dl((1,2),1)
assign(2,3) dl((2,1),1) dl((2,2),7)
assign(3,1) dl((3,1),6) dl((3,2),12)
SATISFIABLE
Models : 1+
Calls : 1
Time : 0.039s (Solving: 0.00s 1st Model: 0.00s Unsat: 0.00s)
CPU Time : 0.002s
\end{lstlisting}
\end{adjustbox}
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east,xshift=-1em,yshift=-2.2cm] at (current page.north east){\usebox\solution};
\end{tikzpicture}
\end{frame}
% ----------------------------------------------------------------------
%
%%% Local Variables:
%%% mode: latex
%%% TeX-master: "../../main"
%%% End: