4
$\begingroup$

I am new to Mathematica, trying to use it to study network structure. I am having trouble with creating this code.

Here are the steps I need to do:

  • First, generate a graph. Let's say a regular graph with 10 vertices and degree 5. Since the RegularGraph command is no longer usable (Combinatorica has been replaced), I had to make do with
RandomGraph[DegreeGraphDistribution[ConstantArray[5, 10]]]

Is there any better suggestion?

  • Second, create a dataset. For simplicity:
d = Tuples[{1, 2}, 10]
  • Third, assign the value in each row of the above dataset to the vertice in the graph. This is where I got stuck. I could not find any documentation regarding this issue. Since I might not have been clear on what I want to do, I will give an example. In the above graph, we have 10 vertices. Let's call the 10 vertices x1,x2,x3,x4,x5,x6,x7,x8,x9,x10. The first row of my created dataset has the value:
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}

So I want to set x1=1,x2=1,...,x10=1.

  • Finally, do an function on the vertice given their connection. For example, in the above graph, since x1, x2, x3 are connected, I want to create a function f(x1)=x1+x2+x3. I have no clue on how to do this part as well.

Thank you very much!

$\endgroup$
4
  • 1
    $\begingroup$ Wouldn't you want RandomGraph[DegreeGraphDistribution[ConstantArray[5, 10]]] for a 10 node regular graph with degree 5? $\endgroup$ Aug 12, 2022 at 22:04
  • $\begingroup$ Thanks! I fixed it $\endgroup$ Aug 12, 2022 at 22:05
  • $\begingroup$ Make sure you check out her help guides it the help documentation, particularly: guide/GraphConstructionAndRepresentation guide/GraphPropertiesAndMeasurements guide/GraphsAndMatrices $\endgroup$ Aug 12, 2022 at 22:15
  • $\begingroup$ AdjacencyMatrix[graph] might be useful. $\endgroup$ Aug 12, 2022 at 22:27

1 Answer 1

5
$\begingroup$

First we create the graph and as the graph has 10 vertices, 10 tuples:

gr = RandomGraph[DegreeGraphDistribution[ConstantArray[5, 10]]]
d = Take[Tuples[{1, 2}, 4], 10]

enter image description here

Then we assign the tuples to vertices:

Graph[gr, VertexLabels -> Table[i -> ToString@d[[i]], {i, 10}]] 

enter image description here

Finally we get the adjacency matrix:

AdjacencyMatrix[gr] // MatrixForm

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.