MathGroup Archive 2002

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

Search the Archive

Re: Dependance Graphs

At 01:30 AM 1/15/2002, Oleg Burd wrote:
>G'day mathgroup,
>I have some general questions on Implementation of dependencies and
>properties in Mathematica.
>I want to replicate a structure with certain properties. For example Product
>"Building", has Property "Stock", Stock = {FirstStock, SecondStock,
>ThirdStock }
>Stock has Flat = {RightFlat, LeftFlat},
>Flat has Properties  = {Owner, Price, Area}.
>The way I found to work with such constructions in Mathematica is ^=:
>My Questions are:
>Is there any other smarter ways to build such dependencies up?
>How can I automatically from Properties Lists {FirstStock, SecondStock,
>ThirdStock }, {RightFlat, LeftFlat},  {Owner, Price, Area} and
>DependanceList = {Stock, Flat, Properties}
>(the list which shows which property refers to which one) generate all
>objects of type:
>Property[Flat[Stock[Building]]] ?
>And finally how can one visualize it?
>Any help or comments will be appreciated.

It depends on what you want to do. Do all these properties exist for each 
building? If so, I would try creating a datatype and interface functions 
for working with that datatype. It's a little bit like OOP. First define 
how the data is organized in the datatype. Usually, this is done by 
position. For example,

Building[Stock[Flat[owner, price, area], Flat[owner, price, area]], ..]

The Building function holds 3 Stocks. The Stock function holds 2 Flats. The 
Flat function holds 3 values.

Now you create a function to create a default building with no settings.

CreateBuilding[] :=
Module[{flat, stock},
   flat = Flat[None,None,None];


If you don't like those defaults, you can add arguments or options to 
control the defaults.

Then, you need some commands for setting and getting the values.


SetProperty[bldg_, {stock_, flat_, prop_}, val_] :=
  s=stock/.{"FirstStock"->1, "SecondStock"->2, "ThirdStock"->3} ;
  f=flat/.{"LeftFlat"->1, "RightFlat"->2} ;
  p=prop/.{"Owner"->1, "Price"->2, "Area"->3};
  bldg[[s,f,p]] = val;

GetProperty[bldg_, {stock_, flat_, prop_}] :=
  s=stock/.{"FirstStock"->1, "SecondStock"->2, "ThirdStock"->3} ;
  f=flat/.{"LeftFlat"->1, "RightFlat"->2} ;
  p=prop/.{"Owner"->1, "Price"->2, "Area"->3};

Now lets take it for a spin.

SetProperty[HomeBuilding, {"SecondStock","LeftFlat","Price"}, 1000]

This changes the definition of the object.



And you can retrieve information without knowing the internal representation.

GetProperty[HomeBuilding, {"SecondStock","LeftFlat","Price"}]


Omega Consulting
"The final answer to your Mathematica needs"

Spend less time searching and more time finding.

  • Prev by Date: Re: Intersection Ellipse & Circle
  • Next by Date: Oscillatory Integrand
  • Previous by thread: Dependance Graphs
  • Next by thread: Front end: Window properties