[eclipse-clp-users] instantiation fault while ic:labeling

From: Oliver Scheickl <scheickl_at_...1...>
Date: Mon, 12 Oct 2009 15:52:01 +0200
Dear all,

In my little program I get an "instantiation fault" error message when
ic:labeling starts. Maybe you can help me out of that issue.

My problem to solve is quite simple: Given a graph consisting of connected
edges; some of the edges can form a path. I want to distribute weights for
the edges such that a) the weight of each edge does not exceed a certain
value and b) the sum of weights of all edges of a path does also not exceed
a certain value.

Here is the complete ECLiPSe program. The example consists of only one path
with three edges. The maximum edge weight is 3, the maximum path weight is
10:

----------------------snip-------------------------
:- lib(ic).
:- local struct(edgeWeight(edge, weight)).

% facts (one path consisting of three edges)
path(f1, node1, node4).

edge(s1, node1, node2).
edge(s2, node2, node3).
edge(s3, node3, node4).


% the main goal to solve
solve(EdgeWeights) :-
    % fetch all edges and construct list EdgeWeights,
    % one struct in list for each edge; the weight of
    % each edge is to be found in the intervall 1..3
    findall(E, edge(E, _, _), Edges),
    (foreach(Edge, Edges),
     foreach(EdgeWeight, EdgeWeights) do
        EdgeWeight = edgeWeight{edge:Edge, weight:Weight},
        Weight :: 1..3
    ),

    % fetch all paths; for each path the sum of edge
    % weights must be smaller than 10
    findall(P, path(P, _, _), Paths),
    (foreach(Path, Paths), param(EdgeWeights) do
        % fetch all edges of one path
        allEdges(Path, Edges),
        % sum up the weights
        weightSum(Edges, EdgeWeights, Sum),
        % the only constraint
        Sum #< 10
    ),

    labeling(EdgeWeights)
    .


% sum up the weight of some edges
weightSum(    Edges,            % a list of Edges
            EdgeWeights,    % list of EdgeWeights of all edges
            WeightSum) :-    % the sum of all wrights of edges in Edges list
    (foreach(Edge, Edges), fromto(0, In, Out, WeightSum), param(EdgeWeights)
do
        weight(Edge, EdgeWeights, Weight),
        Out is In + Weight
    ).

% get the Weight of Edge from EdgeWeights
weight(Edge, EdgeWeights, Weight) :-
    member(edgeWeight{edge:Edge, weight:Weight}, EdgeWeights).

% get all edges of one path
allEdges(Path, Edges) :-
    path(Path, From, To),
    edgePath(From, To, [], Edges).

edgePath(Hop, Hop, _, []).
edgePath(From, To, Contained, [First | Rest]) :-
    edge(First, From, X),
    not(member(X, Contained)),
    edgePath(X, To, [X | Contained], Rest).
----------------------snip-------------------------


What do you think of that solution in general? What am I doing wrong to get
that error?

Thanks for your help.
Best regards,
Oliver.
Received on Mon Oct 12 2009 - 13:52:14 CEST

This archive was generated by hypermail 2.3.0 : Wed Sep 25 2024 - 15:13:20 CEST