w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Good data structure or database to represent objects and transitions between objects?

This sounds like a problem for a standard graph.

Let each resource be a node and connect 2 nodes if there's a transition between them, with the edge weight being the transition ratio.

These edges will probably need to be directed, and, if the transitions are inverses, have 2 edges, one in either direction. Alternatively, if the transitions are inverses, you can have an undirected graph and define the edge weight as the transition ratio from the 'smallest' node to the 'largest' (you'll need to have some possibly arbitrary ordering of node). By "transitions are inverses" I mean, if you go from any resource to any other resource, you can also go back again, and, if you do so, you get back the same amount as you originally started with (although, this doesn't appear to hold from the example).

Then you'll probably have to use breadth-first search (or similar) to determine getting from one resource to another.

In terms of SQL, a possible structure is as follows:

Resource
  ID, ...

Transition
  ResourceID1, ResourceID2, Cost




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.