sendmore(Digits) :- Digits = [S,E,N,D,M,O,R,Y], Digits :: [0..9], Carries = [C1,C2,C3,C4], Carries :: [0..1], alldifferent(Digits), S # |
sendmore(Digits) :- Digits = [S,E,N,D,M,O,R,Y], Digits :: [0..9], viewable_create(digits, Digits), ... ... labeling(Carries), labeling(Digits). |
S | E | N | D | ||
+ | M | O | R | E | |
M | O | N | E | Y |
⎛ ⎜ ⎜ ⎝ |
|
⎞ ⎟ ⎟ ⎠ |
or it could be declared in the program using ECLiPSe array syntaxviewable_create(equation,[[0, S, E, N, D],[0, M, O, R, E],[M, O, N, E, Y]]
Three points should be noted here,viewable_create(equation,[]([](0, S, E, N, D), [](0, M, O, R, E), [](M, O, N, E, Y)))
sendmore(Digits) :- Digits = [S,E,N,D,M,O,R,Y], Digits :: [0..9], viewable_create(equation, []([](0, S, E, N, D), [](0, M, O, R, E), [](M, O, N, E, Y)), array([flexible,fixed], any)), ... ... labeling(Carries), labeling(Digits), viewable_expand(equation, 1, [C1, C2, C3, C4, 0]). |
:-lib(viewable). sendmore(Digits) :- Digits = [S,E,N,D,M,O,R,Y], Digits :: [0..9], viewable_create(equation, []([](0, S, E, N, D), [](0, M, O, R, E), [](M, O, N, E, Y)), array([flexible,fixed], numeric_bounds), [["send", "more", "money"], ["ten thousands", "thousands", "hundreds", "tens", "units"]]), Carries = [C1,C2,C3,C4], Carries :: [0..1], alldifferent(Digits), S # |
:-lib(graph_algorithms). :-lib(viewable). :-lib(ic). test:- make_graph(7, [e(1,2,F12), e(2,3,F23), e(2,4,F24), e(3,5,F35), e(4,5,F45), e(4,6,F46), e(5,6,F56), e(6,3,F63), e(6,7,F67)], Graph), Flows = [F23,F24,F35,F45,F46,F56,F63], Flows :: 0..5, (for(Node, 2, 6), param(Graph) do graph_get_incoming_edges(Graph, Node, InEdges), graph_get_adjacent_edges(Graph, Node, OutEdges), (foreach(e(_From, _To, Flow), InEdges), foreach(Flow, InFlow) do true), (foreach(e(_From, _To, Flow), OutEdges), foreach(Flow, OutFlow) do true), sum(InFlow) #= sum(OutFlow) ), F12 #= 9, viewable_create(flow_viewable, Graph, graph(fixed), [node_property([0->[name(nodes), label]]), edge_property([0->[name(edges), label]]) ]), labeling(Flows). |
markup | meaning | applicability | required |
name(String) | A unique name to refer to this property | both | yes |
label | This property should be used as the node/edge text label | both | yes |
%———————————————————————- % Example for basic use of ECLiPSe/CPLEX interface % % Distribution problem taken from EuroDecision chapter in D4.1 %———————————————————————- :- lib(eplex_xpress). :- eplex_instance(foo). %———————————————————————- % Explicit version (clients A-D, plants 1-3) %———————————————————————- main(Cost, Vars) :- Vars = [A1, B1, C1, D1, A2, B2, C2, D2, A3, B3, C3, D3], foo:(Vars :: 0.0..10000.0), % variables foo:(A1 + A2 + A3 $= 200), % demand constraints foo:(B1 + B2 + B3 $= 400), foo:(C1 + C2 + C3 $= 300), foo:(D1 + D2 + D3 $= 100), foo:(A1 + B1 + C1 + D1 $=< 500), % capacity constraints foo:(A2 + B2 + C2 + D2 $=< 300), foo:(A3 + B3 + C3 + D3 $=< 400), foo:eplex_solver_setup( min( % solve 10*A1 + 7*A2 + 11*A3 + 8*B1 + 5*B2 + 10*B3 + 5*C1 + 5*C2 + 8*C3 + 9*D1 + 3*D2 + 7*D3)), foo:eplex_solve(Cost). |
viewable_create(vars, Vars array([fixed], changeable(foo, any))), |
viewable_create(vars, []([](A1, A2, A3), [](B1, B2, B3), [](C1, C2, C3), [](D1, D2, D3)), array([fixed,fixed], changeable(foo, any))), |
make_graph_symbolic([]('A','B','C','D',1,2,3), [edge(1,'A',A1),edge(2,'A',A2),edge(3,'A',A3), edge(1,'B',B1),edge(2,'B',B2),edge(3,'B',B3), edge(1,'C',C1),edge(2,'C',C2),edge(3,'C',C3), edge(1,'D',D1),edge(2,'D',D2),edge(3,'D',D3)],G), viewable_create(network, G, graph(fixed,changeable(foo,graph_data))), |
- viewable_create/2/3/4
- used to group problem variables for visualisation purposes. Groupings referred to as viewables.
- viewable_expand/3/4
- viewables can be of a fixed size, or can expand and shrink.
- types
- elements of a viewable may be defined as being numeric values or may be any ECLiPSeterm. The type of a viewable will determine how it can be visualised.
- structure
- interesting variables contained within graph structures can be directly annotated using the graph(static) viewable type.
Figure 2.1: Overview of program annotation