[Haskell-cafe] Re: finding the right mathematical model

Heinrich Apfelmus apfelmus at quantentunnel.de
Wed Jul 7 05:42:01 EDT 2010


Günther Schmidt wrote:
> Hi list,
> 
> the problem I have stems from the app I had developed. What my app does 
> is to split the money a hospital receives for a case to the departments 
> involved in a fair way.
> 
> An additional requirement however was to allow the users of the app to 
> re-map any revenue shares credited to certain departments to other 
> departments. Such cases are sometimes due to politics within the 
> hospital and also have more legitimate reasons, like saying the 
> radiology should not receive shares for surgical procedures but those 
> shares should be redirected to the "General surgery" department.
> 
> The feature is already implemented, but I'm not pleased with it, 
> especially since I did not develop a mathematical model for it.
> 
> Details:
> 
> It boils down to model mappings, or rather what sort of data structure 
> would be suited for this kind of thing.
> 
> Dept A is "mapped" to itself
>     A -> A
> 
> Dept B is mapped to Dept C
>     B -> C
> 
> Dept C is mapped to Dept C
>     C -> C
> 
> Dept D is mapped to Dept A
>     D -> A
> 
> It should not be possible to construct looping mappings, ie.
> 
>   1. A -> B
>   2. B -> C
>   3. C -> A
> 
> .......
> 
> 
> What sort of model would be suitable to describe this, some sort of matrix?

You probably want a graph where the nodes represent departments and 
edges represent the mappings. To implement graphs in Haskell, have a 
look at the functional graph library

   http://hackage.haskell.org/package/fgl

If that's too complicated for you and your graphs are really small, you 
can also use a toy implementation like

   type Graph = [(Node,   -- Department
                 [Node])  -- List of Departments it shares revenue to
                ]

To test whether a graph has cycles ("looping mapping"), you can use a 
depth-first search.


Regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com



More information about the Haskell-Cafe mailing list