Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2002
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2002

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

Search the Archive

Re: Dependance Graphs

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32517] Re: [mg32333] Dependance Graphs
  • From: Omega Consulting <omega_consulting at yahoo.com>
  • Date: Fri, 25 Jan 2002 02:57:46 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

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 ^=:
>Area[RightFlat[FirstStock[Home_Building]]]=100;
>Owner[LeftFlat[SecondStock[Home_Building]]]="Robert";
>Price[RightFlat[FirstStock[Home_Building]]]=50000;
>
>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.
>
>Thanks
>Oleg.

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];
   stock=Stock[flat,flat];
   Building[stock,stock,stock]
]

HomeBuilding=CreateBuilding[];

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.

Attributes[SetProperty]={HoldFirst}

SetProperty[bldg_, {stock_, flat_, prop_}, val_] :=
Module[{f,s,p},
  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_}] :=
Module[{f,s,p},
  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]]
]

Now lets take it for a spin.

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

This changes the definition of the object.

HomeBuilding

Building[Stock[Flat[None,None,None],Flat[None,None,None]],
   Stock[Flat[None,1000,None],Flat[None,None,None]],
   Stock[Flat[None,None,None],Flat[None,None,None]]]

And you can retrieve information without knowing the internal representation.

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

1000

--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"

Spend less time searching and more time finding.
http://www.wz.com/internet/Mathematica.html



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