🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #4282

Duplicate Solutions

#4282
From: Pat Chkoreff
Date: Wed, 14 Mar 1990 01:32
35 lines
1664 bytes
Occasionally I have written a predicate that yields duplicate solutions, and
I've wondered how to make each solution occur uniquely.  For example, I have
a multigraph:

	node(X).             % X is a node.
	edge(E, X, Y).       % E is a directed edge from node X to node Y.

I write a predicate:

	joined(X, Y).        % There exists an edge from node X to node Y.

Initially I write:

	joined(X, Y) :-
		edge(_, X, Y).

But this version has duplicate solutions when there are multiple edges from
X to Y.  The most straightforward way I have been able to avoid this is:

	joined(X, Y) :-
		bagof(E, edge(E,X,Y), _).

The use of bagof/3 seems wasteful.  I could use setof/3 instead and think of
the set of edges as a "hyperedge" from X to Y, but I don't really need to
compute the hyperedge -- just determine the existence of one.

Usually, the existence of duplicate solutions makes me change either my data
model or my algorithms to avoid them.  But in this example, my data model is
straightforward, joined/2 seems like a natural thing to have, and duplicate
solutions bother me (I'm not sure why, though).  What would you do to avoid
duplicate solutions, or would you even bother?


Patrick Chkoreff   719-590-5983
{hpfcla,hplabs}!hpldola!patch
Technical Details
Message-ID: <11500023@hpldola.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!bloom-beacon!bu.edu!purdue!decwrl!ucbvax!hplabs!hpfcso!hpldola!patch

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!mcgill-vision!bloom-beacon!bu.edu!purdue!decwrl!ucbvax!hplabs!hpfcso!hpldola!patch
From: patch@hpldola.HP.COM (Pat Chkoreff)
Newsgroups: comp.lang.prolog
Subject: Duplicate Solutions
Message-ID: <11500023@hpldola.HP.COM>
Date: 14 Mar 90 01:32:48 GMT
Organization: HP Elec. Design Div. -ColoSpgs
Lines: 35