\begin{figure}[!h]
\begin{center}
\includegraphics[width=3.5in]{../tim/cirt.pdf}
\end{center}
\caption{A qualitative network: $Sw_i$ , $B_i$ denote switches and bulbs.
The network repeats the structure labeled
$\{A,B,C\}$ three times. Between each repeat are 
connectors that {\em open} or {\em close}  switches depending on
whether or not some bulb is glowing or dark.
}
\label{fig:cirtt}
\end{figure}

\section{Case Studies}

\subsection{Network Design}

%Such networks have the following features:
%\bi
%\item
%{\em Units} are defined according to  constraints between their {\em input/output} variables;
%\item
%{\em Units} are connected in a network where the output of some units
%are the input to others.
%\item
%Something {\em flows} around the network and {\em conservation laws} apply
%(e.g. in-flow has to equal out-flow).
%\item
%Sometimes, the network is built from a component libraries. Hence, it may contain repeated structures.
%\ei
%
%\noindent
%Such a network could represent many situations including
%\bi
%\item
%Water flowing in pipes in an industrial
%plant; 
%\item
%Customers moving through a web site while being directed towards services that potentially 
%interest them;
%\item
%The electrical circuit shown in \fig{cirtt}.
%\ei

This first example is motivated as follows.
Early in the design life cycle, the  general structure of the
solution may be known, but the details may yet to be determined.
That is,  even if precise quantitative values are unknown,
the {\em qualitative} features of the solution may be defined.
For example,
the network topology of the product is defined
and the 
general nature of the network constraints are known.
However, 
all that might be known about the 
numerics is their sign- 
$\{+,-,0\}$ 
representing {\em positive}, {\em negative}, and {\em zero}
quantities (respectively).


Despite these unknowns, we still may
want to use the design to assess different
options.
For example, suppose the goal of the 
circuit in \fig{cirtt} is to illuminates some region.
If analysts are worried about power surges burning out
the bulbs, then they might consider adding in expensive
surge protectors
upstream of each the bulb. 
Suppose management has become
concerned about the cost of adding these
surge protectors. The engineering team might then
want to find
the {\em fewest} bulbs
that {\em most} need surge protection.

For the purposes of exposition, we will assume that
\fig{cirtt} is a qualitative circuit.
Qualitative arithmetic can be define using the following look-up table;
e.g. if two {\em positive} qualities are added together, the result is also {\em positive}:
\begin{center} \begin{minipage} {.8\linewidth} \begin{alltt}\footnotesize
sum(+,+,+).   sum(+,0,+). sum(+,-,Any).
sum(0,+,+).   sum(0,0,0). sum(0,-,-).
sum(-,+,Any). sum(-,0,-). sum(-,-,-).
\end{alltt} \end{minipage} \end{center}
In nondeterministic systems, the outputs are not fully determined by the inputs.
For example, the above table reports that 
adding a {\em positive} and a {\em negative}
quality can produce a new quality of $Any$ sign. 
Decision making over nondeterministic models
is not a simple matter since there is no definitive
best policy. Rather, qualitative decision making
must sample the space of possible competing influences, looking for decisions
which {\em usually} improve the current situation.

The space of possible competing influences can be large.
Even a design as small as
\fig{cirtt} has over 35,000 different solutions.
To show the size of the design space,
some more information is required about 
the bulbs, switches of that figure.
For example, the first line of the following table
says that a blown bulb is always dark, and has zero amps.
Also, the last line 
({\tt switch(on,0,Any)}) records that 
if a switch is on, there is zero voltage drop
across.
\begin{center} \begin{minipage} {.9\linewidth} \begin{alltt}\footnotesize
%bulb(Mode,Light,Volts,Amps)
 bulb(blown,dark,  Any, 0).
 bulb(ok,   light, +,   +).
 bulb(ok,   light, -,   -).
 bulb(ok,   dark,  0,   0).

%num(Light, Glow).   %switch(State,Volts,Amps)
 num( light, 1).      switch(off,   Any,  0).
 num( dark,  0).      switch(on,    0,    Any).
\end{alltt} \end{minipage} \end{center}
\begin{figure}[!b]
{\scriptsize \begin{alltt}
  1  circuit(switch(Sw1,VSw1,C1),
  2          bulb(B1,L1,VB1,C1),
  3          switch(Sw2,VSw2,C2),
  4          bulb(B2,L2,VB2,C2),
  5          switch(Sw3,VSw3,CSw3),
  6          bulb(B3,L3,VB3,CB3),
  7          Glow) :-
  8      VSw3 = VB3,
  9      sum(VSw1, VB1, V1),   %  9 options
 10      sum(V1,VB3,+),        %  1 option
 11      sum(VSw2,VB2,VB3),    %  9 options
 12      switch(Sw1,VSw1,C1),  %  2 options
 13      bulb(B1,L1,VB1,C1),   %  4 options
 14      switch(Sw2,VSw2,C2),  %  2 options
 15      bulb(B2,L2,VB2,C2),   %  4 options
 16      switch(Sw3,VSw3,CSw3),%  2 options
 17      bulb(B3,L3,VB3,CB3),  %  4 options
 18      sum(CSw3,CB3,C3),     %  9 options
 19      sum(C2,C3,C1),        %  9 options
 20      num(L1,N1),
 21      num(L2,N2),
 22      num(L3,N3),
 23      Glow is N1+N2+N3.
\end{alltt}}
\caption{Conversation rules of \fig{cirttiny}.}\label{fig:cirt}
\end{figure}
\fig{cirt} repeats three structures labeled $\{A,B,C\}$.
Within each structure,
certain conservation laws apply
about circuits in parallel and series.
These laws are represented in the Prolog of
\fig{cirt}; e.g.  line 11 says the sum of the voltages across switch
{\em SW2} and bulb {\em B2} is the same as the voltage across the
parallel bulb {\em B3}.
Each line of \fig{cirt} is labeled with the number of possibilities
it condones: i.e.  9*1*9*2*4*2*4*2*4*9*9=3,359,232.  When  copied
three times in \fig{cirtt} these implies a space of up to
$(3,359,232)^3=10^{19}$ options. Many of these possibilities are ruled
out by inter-component constraints; nevertheless the constraints
of \fig{cirtt} can still succeed 35,228 times.


Enter treatment learning. Instead of exploring tens of 
\begin{wrapfigure}{r}{1.3in}
{\footnotesize
\begin{center}
\begin{tabular}{c}
Untreated circuit \\
\begin{barenv} \setstyle{\sffamily} \setwidth{8}
\setnumberpos{none} \setstretch{1} \setyaxis{0}{45}{15}
\setxaxis{0}{9}{1}
\bar{0}{8}  %0
\bar{22}{8} %1
\bar{43}{8} %2
\bar{21}{8} %3
\bar{6}{8}  %4
 \bar{6}{8} %5
\bar{1}{8}  %6
\bar{0}{8}  %7
\bar{0}{8}  %8
\bar{0}{8}  %9
\end{barenv}
\end{tabular}
\end{center}}
\caption{Frequency count of number of bulbs glowing in the 35,228
solutions of {\tt circuits} of
\fig{cirtt}.}\label{fig:baseline}\label{fig:run1}
\end{wrapfigure}
thousands of options, our contrast set learner just seeks the smallest {\em differences}
that distinguishes the lightest circuits from the darkest circuits.
This is simple to operationalize: in the 35,228 solutions,
each of the nine bulbs either glows or is dark. Hence, we can give the contrast
set learner 35,228 examples, each labeled with the class $1,2,3,{\ldots}9$.
\fig{run1} shows the distribution of those examples- note how in the usual case,
most of the bulbs are dark.

\fig{whatif3} shows three rounds of contrast set learning. Each round $i$ 
imposes the 
treatments learned at round $i-1$ as additional constraints to the circuit.
The circuit is then run again and only those solutions satisfying the new
constraints
are reported. Each row of \fig{whatitf3} shows the top two treatment
representing the number of glowing bulbs. 
Our contrast set learner then returns the rules 

Using contrast set learning, we can explore this very
large 
space of options to achieve our design goals
of finding  the fewest
bulbs requiring the most surge protection. To do this,
first we assume 
that the {\em more} bulbs that shine, the better the surge
protection. Second, we use treatment learning to 
find the fewest settings to \fig{cirtt} to keep the most
bulbs shining.

Prior to treating the circuit, the average
number of shining is very low (see~\fig{run1}).
Treatment learning was then applied to optimize bulbs glowing.

3264
648
\vspace{2cm}
\begin{figure}[!ht]
\begin{center}
{\footnotesize
\begin{tabular}{|c@{~}c@{~}c|}\hline
round1 &
if Sw2C=off then ... & if Sw3C=on then ...~\\&&~\\
&
\begin{barenv}
\setstyle{\sffamily} \setwidth{8} \setnumberpos{none}
\setstretch{1} \setyaxis{0}{48}{15} \setxaxis{0}{9}{1}
\bar{0}{8} %0
\bar{0}{8} %1
\bar{0}{8} %2
\bar{0}{8} %3
\bar{47}{8} %4
 \bar{48}{8} %5
\bar{3}{8} %6
\bar{2}{8} %7
\bar{0}{8} %8
\bar{0}{8} %9
\end{barenv}
&
\begin{barenv}
\setstyle{\sffamily} \setwidth{8} \setnumberpos{none}
\setstretch{1}  \setyaxis{0}{46}{15} \setxaxis{0}{9}{1}
\bar{0}{8} %0
\bar{0}{8} %1
\bar{0}{8} %2
\bar{0}{8} %3
\bar{15}{8} %4
 \bar{46}{8} %5
\bar{35}{8} %6
\bar{4}{8} %7
\bar{0}{8} %8
\bar{0}{8} %9
\end{barenv}\\\hline
&&~\\&&~\\\hline
round 2 &
when Sw2c=off then&  when Sw2c=off then\\
& if Sw1C=on  then ... & if  B3C=ok then ...~\\&&~\\
&
\begin{barenv}
\setstyle{\sffamily} \setwidth{8} \setnumberpos{none}
\setstretch{1} \setyaxis{0}{48}{15} \setxaxis{0}{9}{1}
\bar{0}{8} %0
\bar{0}{8} %1
\bar{0}{8} %2
\bar{0}{8} %3
\bar{41}{8} %4
 \bar{42}{8} %5
\bar{9}{8} %6
\bar{8}{8} %7
\bar{0}{8} %8
\bar{0}{8} %9
\end{barenv}&
\begin{barenv}
\setstyle{\sffamily} \setwidth{8} \setnumberpos{none}
\setstretch{1}  \setyaxis{0}{46}{15} \setxaxis{0}{9}{1}
\bar{0}{8} %0
\bar{0}{8} %1
\bar{0}{8} %2
\bar{0}{8} %3
\bar{15}{8} %4
 \bar{46}{8} %5
\bar{35}{8} %6
\bar{4}{8} %7
\bar{0}{8} %8
\bar{0}{8} %9
\end{barenv}\\
&&~\\&&~\\\hline
round3 & 
when Sw2C=off & when Sw2C=off \\
& and Sw1C=on then &  and Sw1C=on then \\
& if  B3C=ok  then ... & if Sw3C=on then ...~\\&&~\\
&
\begin{barenv}
\setstyle{\sffamily} \setwidth{8} \setnumberpos{none}
\setstretch{1} \setyaxis{0}{32}{15} \setxaxis{0}{9}{1}
\bar{0}{8} %0
\bar{0}{8} %1
\bar{0}{8} %2
\bar{0}{8} %3
\bar{18}{8} %4
 \bar{21}{8} %5
\bar{32}{8} %6
\bar{29}{8} %7
\bar{0}{8} %8
\bar{0}{8} %9
\end{barenv}
&
\begin{barenv}
\setstyle{\sffamily} \setwidth{8} \setnumberpos{none}
\setstretch{1}  \setyaxis{0}{50}{15} \setxaxis{0}{9}{1}
\bar{0}{8} %0
\bar{0}{8} %1
\bar{0}{8} %2
\bar{0}{8} %3
\bar{0}{8} %4
 \bar{25}{8} %5
\bar{50}{8} %6
\bar{25}{8} %7
\bar{0}{8} %8
\bar{0}{8} %9
\end{barenv}~\\
&&~\\
&&~\\
\hline
\end{tabular}}
\end{center}
\caption{Run\#3 of TAR2 over the data seen in
\fig{run3}.}\label{fig:whatif3}
\end{figure}

\begin{figure}[!ht]
\begin{center}
{\footnotesize
\begin{tabular}{|c@{~}c@{~}c|}\hline
round1 &
if Sw2C=off then ... & if Sw3C=on then ...~\\&&~\\
&
\begin{barenv}
\setstyle{\sffamily} \setwidth{8} \setnumberpos{none}
\setstretch{1} \setyaxis{0}{48}{15} \setxaxis{0}{9}{1}
\bar{0}{8} %0
\bar{0}{8} %1
\bar{0}{8} %2
\bar{0}{8} %3
\bar{47}{8} %4
 \bar{48}{8} %5
\bar{3}{8} %6
\bar{2}{8} %7
\bar{0}{8} %8
\bar{0}{8} %9
\end{barenv}
\\
&&~\\&&~\\\hline
round 2 &
when Sw2c=off then&  when Sw2c=off then\\
& if Sw1C=on  then ... & if  B3C=ok then ...~\\&&~\\
&
\begin{barenv}
\setstyle{\sffamily} \setwidth{8} \setnumberpos{none}
\setstretch{1} \setyaxis{0}{48}{15} \setxaxis{0}{9}{1}
\bar{0}{8} %0
\bar{0}{8} %1
\bar{0}{8} %2
\bar{0}{8} %3
\bar{41}{8} %4
 \bar{42}{8} %5
\bar{9}{8} %6
\bar{8}{8} %7
\bar{0}{8} %8
\bar{0}{8} %9
\end{barenv}\\
&&~\\&&~\\\hline
round3 & 
when Sw2C=off & when Sw2C=off \\
& and Sw1C=on then &  and Sw1C=on then \\
& if  B3C=ok  then ... & if Sw3C=on then ...~\\&&~\\
&
\begin{barenv}
\setstyle{\sffamily} \setwidth{8} \setnumberpos{none}
\setstretch{1} \setyaxis{0}{32}{15} \setxaxis{0}{9}{1}
\bar{0}{8} %0
\bar{0}{8} %1
\bar{0}{8} %2
\bar{0}{8} %3
\bar{18}{8} %4
 \bar{21}{8} %5
\bar{32}{8} %6
\bar{29}{8} %7
\bar{0}{8} %8
\bar{0}{8} %9
\end{barenv}
\\
&&~\\
&&~\\
\hline
\end{tabular}}
\end{center}
\caption{Run\#3 of TAR2 over the data seen in
\fig{run3}.}\label{fig:whatif3}
\end{figure}
 ScaleFactor) * log(Kloc)) + A + log(EffortMultiplier)
