Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Evaluate a function along a path in a graph
ResourceFunction["GraphPathAggregate"][g,f,path] evaluates f[w1,w2,…] for a sequence of edge weights along a path in graph g. | |
ResourceFunction["GraphPathAggregate"][g,f] represents an operator form of ResourceFunction["GraphPathAggregate"] that can be applied to paths. |
"EdgeProperty" | EdgeWeight | edge property to use for computation |
"VertexProperty" | None | vertex property to use for computation |
Sum the EdgeWeight along a path in a Graph:
In[1]:= | ![]() |
Out[1]= | ![]() |
Use a path specified by edges:
In[2]:= | ![]() |
Out[2]= | ![]() |
Compute multiple paths:
In[3]:= | ![]() |
Out[3]= | ![]() |
When a path is specified by vertices, all applicable paths will be evaluated:
In[4]:= | ![]() |
Out[4]= | ![]() |
Use the operator form to map over multiple paths:
In[5]:= | ![]() |
Out[6]= | ![]() |
Any operator can be used:
In[7]:= | ![]() |
Out[7]= | ![]() |
In[8]:= | ![]() |
Out[8]= | ![]() |
Any edge property can be used for computation:
In[9]:= | ![]() |
Out[9]= | ![]() |
In[10]:= | ![]() |
Out[10]= | ![]() |
If a property is not defined on an edge, Missing[…] will be returned:
In[11]:= | ![]() |
Out[11]= | ![]() |
Specify a vertex property to extract values from along the path:
In[12]:= | ![]() |
Out[12]= | ![]() |
Do a computation on both vertices and edges along a path:
In[13]:= | ![]() |
Out[13]= | ![]() |
Compute only with vertex properties:
In[14]:= | ![]() |
Out[14]= | ![]() |
If edge weights are not explicitly provided then they are treated as missing:
In[15]:= | ![]() |
Out[15]= | ![]() |
Giving one edge weight explicitly sets all others to the default of 1:
In[16]:= | ![]() |
Out[16]= | ![]() |
Define a graph with transition probabilities of an experiment that first flips a biased coin and then rolls a die; if the coin lands on an edge, don't roll the die:
In[17]:= | ![]() |
Out[17]= | ![]() |
Compute the probability of rolling a 6 by first finding all paths:
In[18]:= | ![]() |
Out[18]= | ![]() |
Sum the probabilities of the paths:
In[19]:= | ![]() |
Out[19]= | ![]() |
Wolfram Language 14.0 (January 2024) or above
This work is licensed under a Creative Commons Attribution 4.0 International License