An additive function with capability to retrieve individual components

30 Views Asked by At

Assume a set of points in a path $A,B,C,D$ and $E$. Starting from point $A$ assuming single direction there are 4 possible paths as $AB, ABC, ABCD, ABCDE$ with identifies 1 to 4 representing each path.

The costs(can be negative) associated with each segment (between two points) is different and is dependent on the path chosen (from the above 4). For example the cost for path $AB$ is 5 when path 1$(AB)$ is chosen and the cost for path segment $AB$ is 4 when path 2$(ABC)$ is chosen. For a given path the cost between segments remain the same.

Assume for all 4 paths above the cost of path segment $AB$ is 5, 4, 9,-2 in that order.

The total cost for all 4 paths for segment $AB$ is $Cost(AB) = 5+4+9-2 = 16$

After I have done this I need to retrieve the cost associated with this segment for path 2$(ABC)$. So when I use the path index with some function $f$ I need to get the value 4. But the overall value should be 16 unless and index is used.

Is this possible via an additive function? If so what are the best options for this kind of a problem?