0

I am working on a system, when given a bank of different types of elements will create a directed acyclic graph connecting some or all the elements. Each element has some input A and an output B. When building the Graph, the system will need to make sure, the output of the previous node, matches the input of the current one.

The input and output of the nodes are to make sure only certain types of elements are connected

The elements would look like this

ElementName : Input -> Output

Possibly with multiple inputs/output, or with no outputs(See below).

One : X -> Y
Two : Y -> Z,F
Three : Y, Z -> W
Four : Z -> F
Five : F -> NULL

Note:

We are talking about a lot of different elements, 30 or so now, but the plan is to add more as time goes on.

This is part of a project to do a procedural generated narrative. The nodes are individual quests. The inputs are what you need to start the quest. The outputs are how the story state is effected.

Problem:

I have seen several different approaches to generating a random DAG, not one for making a DAG from some preset connection requirements(with rules on connecting them). I also want some way of limiting complexity of the graph. i.e limit the number of branches they can have.

Idea of what I want:

You have a bunch of different types of legos in a bin, say 30. You have rules on connecting the Legos.

Blue -> Red
Blue -> White
Red -> Yellow
Yellow -> Green/Brown
Brown -> Blue

As you all know, in addition to a color each lego had a shape.So 2 blue legos may not be the same type of lego. So The goal is to build a large structure that fits our rules. Even with our rules, we can still connect the legos in a bunch of different structures.

P.S. I am hoping this is not to general of a question. If it is, please make a note and I will try to make it more specific.

error_null_pointer
  • 457
  • 1
  • 6
  • 21
  • Your terminology makes discussion unwieldy as node is synonym for vertex & the bank of nodes containing inputs & outputs is itself the input for the desired random DAG generator. Is it correct to restate the problem as 'starting with a direct graph, how can you get a random directed acyclic subgraph'? – Pikalek Feb 16 '16 at 20:13
  • I fixed the terminology. I also added an example under "Idea of what I want" I'm not trying to get a sub graph, I think what I didn't get across was the fact that different elements may have the same outputs, but they are not necessarily be the same. – error_null_pointer Feb 17 '16 at 00:03
  • That's clearer to me - I hadn't picked up that the elements / legos would reoccur. With the revision, it sounds sort of like an [L-system](https://en.wikipedia.org/wiki/L-system); given a starting lego, why not just select randomly from the relevant connection rules? – Pikalek Feb 19 '16 at 01:44
  • That seems to be the type of thing I was looking for. I am doing more research into them now. If you want to make that an answer, I will mark it as correct. – error_null_pointer Mar 03 '16 at 03:07

1 Answers1

1

It sounds like an L-system (aka Lindenmayer system) approach would work:

  • Your collection of Legos is analogous to an alphabet of symbols
  • Your connection rules correspond to a collection of production rules that expand each symbol into some larger string of symbols
  • Your starting Lego represents the the initial "axiom" string from which to begin construction
  • The resulting geometric structures is your DAG

The simplest approach would be something like: given a Lego, randomly select a valid connection rule & add a new Lego to the DAG. From there you could add in more complexity as needed. If you need to skew the random selection to favor certain rules, you're essentially building a stochastic grammar. If the selection of a rule depends on previously generated parts of the DAG it's a type of context sensitive grammar.

Graph rewriting, algorithmically creating a new graph out of base graph, might be a more literal solution, but I personally find that L-systems easier to internalize & that researching them yields results that are not overly academic/theoretical in nature.

L-systems themselves are a category of formal grammars. It might be worth checking into some of those related ideas, but it's pretty easy (for me at least) to get side tracked by theoretical stuff at the expense of core development.

Pikalek
  • 926
  • 7
  • 21