Update background section

This commit is contained in:
Jip J. Dekker 2021-04-12 17:07:50 +10:00
parent 8c6f4572e8
commit 29b31b2a09
No known key found for this signature in database
GPG Key ID: 517DF4A00618C9C3
3 changed files with 31 additions and 32 deletions

View File

@ -1,15 +1,15 @@
% Problem parameters % Problem parameters
enum TOYS;@\Vlabel{line:back-knap-toys}@ enum TOYS;@\Vlabel{line:back:knap:toys}@
array[TOYS] of int: toy_joy;@\Vlabel{line:back-knap-joy}@ array[TOYS] of int: toy_joy;@\Vlabel{line:back:knap:joy}@
array[TOYS] of int: toy_space;@\Vlabel{line:back-knap-space}@ array[TOYS] of int: toy_space;@\Vlabel{line:back:knap:space}@
int: space_left;@\Vlabel{line:back-knap-left}@ int: space_left;@\Vlabel{line:back:knap:left}@
% Decision variables % Decision variables
var set of TOYS: selection;@\Vlabel{line:back-knap-sel}@ var set of TOYS: selection;@\Vlabel{line:back:knap:sel}@
var int: total_joy = sum(toy in selection)(toy_joy[toy]);@\Vlabel{line:back-knap-tj}@ var int: total_joy = sum(toy in selection)(toy_joy[toy]);@\Vlabel{line:back:knap:tj}@
% Constraints % Constraints
constraint sum(toy in selection)(toy_space[toy]) < space_left;@\Vlabel{line:back-knap-con}@ constraint sum(toy in selection)(toy_space[toy]) < space_left;@\Vlabel{line:back:knap:con}@
% Goal % Goal
solve maximize total_joy;@\Vlabel{line:back-knap-obj}@ solve maximize total_joy;@\Vlabel{line:back:knap:obj}@

View File

@ -82,6 +82,7 @@ style=apa,
\newcommand{\Vlabel}[1]{\label[line]{#1}\hypertarget{#1}{}} \newcommand{\Vlabel}[1]{\label[line]{#1}\hypertarget{#1}{}}
\newcommand{\lref}[1]{\hyperlink{#1}{\FancyVerbLineautorefname~\ref*{#1}}} \newcommand{\lref}[1]{\hyperlink{#1}{\FancyVerbLineautorefname~\ref*{#1}}}
\newcommand{\Lref}[1]{\hyperlink{#1}{\FancyVerbLineautorefname~\ref*{#1}}}
\newcommand{\lrefrange}[2]{\FancyVerbLineautorefname{}s~\hyperlink{#1}{\ref*{#1}}--\hyperlink{#2}{\ref*{#2}}} \newcommand{\lrefrange}[2]{\FancyVerbLineautorefname{}s~\hyperlink{#1}{\ref*{#1}}--\hyperlink{#2}{\ref*{#2}}}
\newcommand{\Lrefrange}[2]{Lines~\hyperlink{#1}{\ref*{#1}}--\hyperlink{#2}{\ref*{#2}}} \newcommand{\Lrefrange}[2]{Lines~\hyperlink{#1}{\ref*{#1}}--\hyperlink{#2}{\ref*{#2}}}

View File

@ -130,20 +130,20 @@ Let us introduce the language by modelling the problem from
\end{listing} \end{listing}
The model starts with the declaration of the \glspl{parameter}. The model starts with the declaration of the \glspl{parameter}.
\Lref{line:back-knap-toys} declares an enumerated type that represents all \Lref{line:back:knap:toys} declares an enumerated type that represents all
possible toys, \(T\) in the mathematical model in the example. possible toys, \(T\) in the mathematical model in the example.
\Lref{line:back-knap-joy,line:back-knap-space} declare arrays mapping from toys \Lref{line:back:knap:joy,line:back:knap:space} declare arrays mapping from toys
to integer values, these represent the functional mappings \(joy\) and to integer values, these represent the functional mappings \(joy\) and
\(space\). Finally, \lref{line:back-knap-left} declares an integer \(space\). Finally, \lref{line:back:knap:left} declares an integer
\gls{parameter} to represent the car capacity as an equivalent to \(C\). \gls{parameter} to represent the car capacity as an equivalent to \(C\).
The model then declares its \glspl{variable}. \Lref{line:back-knap-sel} declares The model then declares its \glspl{variable}. \Lref{line:back:knap:sel} declares
the main \gls{variable} \mzninline{selection}, which represents the selection of the main \gls{variable} \mzninline{selection}, which represents the selection of
toys to be packed. \(S\) in our earlier model. We also declare the variable toys to be packed. \(S\) in our earlier model. We also declare the variable
\mzninline{total_joy}, on \lref{line:back-knap-tj}, which is functionally \mzninline{total_joy}, on \lref{line:back:knap:tj}, which is functionally
defined to be the summation of all the joy for the toy picked in our selection. defined to be the summation of all the joy for the toy picked in our selection.
Finally, the model contains a constraint, on \lref{line:back-knap-con}, to Finally, the model contains a constraint, on \lref{line:back:knap:con}, to
ensure we do not exceed the given capacity and states the goal for the solver: ensure we do not exceed the given capacity and states the goal for the solver:
to maximise the value of the variable \mzninline{total_joy}. to maximise the value of the variable \mzninline{total_joy}.
@ -157,30 +157,30 @@ primitive constraints.
Given the assignments Given the assignments
\begin{mzn} \begin{mzn}
TOYS = {football, tennisball, stuffed_lama, stuffed_elephant}; TOYS = {football, tennisball, stuffed_elephant};
toy_joy = [63, 12, 50, 100]; toy_joy = [63, 12, 100];
toy_space = [32, 8, 16, 40]; toy_space = [32, 8, 40];
space_left = 64; space_left = 44;
\end{mzn} \end{mzn}
is the result of flattening for \mzninline{n=2}: the following model is the result of flattening:
\begin{mzn} \begin{mzn}
var 1..2: x_1_1; var 0..1: selection_0;
var 1..2: x_1_2; var 0..1: selection_1;
var 1..2: x_2_1; var 0..1: selection_2;
var 1..2: x_2_2; var 0..175: total_joy:: is_defined_var;
constraint all_different([x_1_1, x_1_2]); constraint int_lin_le([32,8,40],[selection_0,selection_1,selection_2],44);
constraint all_different([x_2_1, x_2_2]); constraint int_lin_eq([63,12,100,-1],[selection_0,selection_1,selection_2,total_joy],0):: defines_var(total_joy);
constraint all_different([x_1_1, x_2_1]); solve maximize total_joy;
constraint all_different([x_1_2, x_2_2]);
\end{mzn} \end{mzn}
This \emph{flat} problem will be passed to some \gls{solver}, which will attempt This \emph{flat} problem will be passed to some \gls{solver}, which will attempt
to determine an assignment to each decision variable \verb|x_i_j| that satisfies to determine an assignment to each decision variable \mzninline{solection_i} and
all constraints, or report that there is no such assignment. \mzninline{total_joy} that satisfies all constraints and maximises
\mzninline{total_joy}, or report that there is no such assignment.
\section{The current \glsentrytext{minizinc} interpreter}% \section{The Current \glsentrytext{minizinc} Interpreter}%
\label{sec:back-mzn-interpreter} \label{sec:back-mzn-interpreter}
\section{Other Constraint Modelling Languages}% \section{Other Constraint Modelling Languages}%
@ -191,5 +191,3 @@ all constraints, or report that there is no such assignment.
\section{Constraint Logic Programming}% \section{Constraint Logic Programming}%
\label{sec:back-clp} \label{sec:back-clp}