Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: WeightingFunction and Showing Graphs with wieghts as Edge Lable

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83118] Re: WeightingFunction and Showing Graphs with wieghts as Edge Lable
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Mon, 12 Nov 2007 05:08:56 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fh6d5q$4kr$1@smc.vnet.net>

mumat wrote:

> I couldn't find this in documentation Mathematica 6.
> 
> First Question: I construct a graph with edge weights selected from a
> given list say, {2,3,5,7}. In the documentaion says:
> 
> SetEdgeWeights[g, e, w]=assigns the weights in the weight list w to
> the edges in edge list \e. Here's one example
> 
> In[1]=t = Wheel[8];k = SetEdgeWeights[t, WeightingFunction ->
> RandomInteger, WeightRange -> {0, 4}]
> 
> In[2]=Edges[k, EdgeWeight]
> 
> But this is not clearly what I want. I want to weights to be selected
> from {2,3,5,7}.

Well, setting WeightRange to the interval [0, 4] is not the appropriate 
way to get values such as 5 and 7.

To get the desired result, one possible way is to get rid of the option 
WeightRange and define your own weighting function that contains the 
desired set of integer values (so it does not use the value provided by 
WeightRange, even the default one, which is the interval [0, 1]).

A good candidate for such a function is RandomChoice. For instance, in 
the example below, we use RandomChoice, with the list of the first four 
primes, in an pure (or anonymous) function.

In[1]:= Needs["Combinatorica`"]
t = Wheel[8]; k =
  SetEdgeWeights[t,
   WeightingFunction -> (RandomChoice[{2, 3, 5, 7}] &)]
Edges[k, EdgeWeight]

Out[2]= (Combinatorica`Graph[{{{1, 8},
    Combinatorica`EdgeWeight -> 2}, {{2, 8},
    Combinatorica`EdgeWeight -> 5}, {{3, 8},
    Combinatorica`EdgeWeight -> 7}, {{4, 8},
    Combinatorica`EdgeWeight -> 2}, {{5, 8},
    Combinatorica`EdgeWeight -> 7}, {{6, 8},
    Combinatorica`EdgeWeight -> 3}, {{7, 8},
    Combinatorica`EdgeWeight -> 2}, {{1, 2},
    Combinatorica`EdgeWeight -> 5}, {{2, 3},
    Combinatorica`EdgeWeight -> 3}, {{3, 4},
    Combinatorica`EdgeWeight -> 5}, {{4, 5},
    Combinatorica`EdgeWeight -> 7}, {{5, 6},
    Combinatorica`EdgeWeight -> 7}, {{6, 7},
    Combinatorica`EdgeWeight -> 5}, {{1, 7},
    Combinatorica`EdgeWeight -> 3}}, {{{0.6234898018587336,
   0.7818314824680298}}, {{-0.22252093395631434`,
   0.9749279121818236}}, {{-0.900968867902419,
   0.43388373911755823`}}, {{-0.9009688679024191, \
-0.433883739117558}}, {{-0.2225209339563146, -0.9749279121818236}}, {{
   0.6234898018587334, -0.7818314824680299}}, {{1., 0}}, {{0, 0}}}])

Out[3]= {{{1, 8}, 2}, {{2, 8}, 5}, {{3, 8}, 7}, {{4, 8}, 2}, {{5, 8},
   7}, {{6, 8}, 3}, {{7, 8}, 2}, {{1, 2}, 5}, {{2, 3}, 3}, {{3, 4},
   5}, {{4, 5}, 7}, {{5, 6}, 7}, {{6, 7}, 5}, {{1, 7}, 3}}


> Question 2: In the other part of the documentation says:
> 
> WeightingFunction can take values Random, RandomInteger, Euclidean, or
> LNorm[n] for nonnegative n, or any pure function that takes two
> arguments, each argument having the form {Integer,{Number,Number}}.
> 
> How can I construct one weightingFunction? Can anyone make one?

This have been done in the example above.

WeightingFunction -> (RandomChoice[{2, 3, 5, 7}] &)

(Note that even though we do not use any argument the function works as 
expected.)

<snip>

Regards,
-- 
Jean-Marc


  • Prev by Date: Re: WeightingFunction and Showing Graphs with wieghts as Edge Lable
  • Next by Date: Re: Problem with Manipulate
  • Previous by thread: Re: WeightingFunction and Showing Graphs with wieghts as Edge Lable
  • Next by thread: Re: Editing one's own default StyleSheet?