Re: CLP(FD) Prolog: help needed with a simple problem
From: Bart Demoen (bmd_at_cs.kuleuven.ac.be)
Date: 03/25/05
- Next message: Matthew Huntbach: "Re: Minsky still posting"
- Previous message: Markus Triska: "Re: CLP(FD) Prolog: help needed with a simple problem"
- In reply to: Chema: "Re: CLP(FD) Prolog: help needed with a simple problem"
- Next in thread: Chema: "Re: CLP(FD) Prolog: help needed with a simple problem"
- Reply: Chema: "Re: CLP(FD) Prolog: help needed with a simple problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 25 Mar 2005 16:52:04 +0100
Chema wrote:
>
>> One way would be to introduce a variable X_e in 0..1 for each edge e
>> (denoting whether it is to be an element of the ST), state that the
>> sum over all these variables must equal |V| - 1, and add additional
>> constraints to prevent cycles.
>
>
> Thank you for your replay and suggestion.
> The problem is just to find this constraints.
> Using this kind of integer programming, I only know if edge X is
> in the spanning tree (1) or not (0), but I have not realized yet
> a way for knowing from which node to wich node edge X goes.
> Right now, I've used a kind of incidence matrix, then I've
> imposed that for each node u, uv in edge, sum x_uv = 1 (exactly
> one edge have to enter in a node, except root), but that doesn't
> prevent cycles.
>
> Chema
You prevent cycles by imposing the constraint that each node is on at least
edge in the subgraph.
E.g.
/*
think of a graph with edges (a,b) (a,c) (b,c)
as [A-[AB,AC], B-[AB,BC], C-[AC,BC]] (just another representation of
the incidence matrix)
the part A- is actually redundant - just a reminder that you
group de edges by node
now impose:
[AB,AC,BC] in 0..1
and the condition that AB+AC+CD = (|V|-1) (2 in this case)
and AB=1 \/ AC=1 && AB=1 \/ BC=1 && AC=1 \/ BC=1
in SW-Prolog this would become ...
*/
:- use_module(library('clp/bounds')).
t([AB,AC,BC]) :-
[AB,AC,BC] in 0..1,
AB+AC+BC #= 2,
AB+AC #>= 1,
AB+BC #>= 1,
AC+BC #>= 1,
label([AB,AC,BC]).
Generalize that to any graph.
Cheers
Bart Demoen
- Next message: Matthew Huntbach: "Re: Minsky still posting"
- Previous message: Markus Triska: "Re: CLP(FD) Prolog: help needed with a simple problem"
- In reply to: Chema: "Re: CLP(FD) Prolog: help needed with a simple problem"
- Next in thread: Chema: "Re: CLP(FD) Prolog: help needed with a simple problem"
- Reply: Chema: "Re: CLP(FD) Prolog: help needed with a simple problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|