1. A method implemented in an electronic device coupled to a network including a plurality of network elements, wherein traffic flows of the network pass through network function chains, wherein each network function is associated with at least one network element, the method comprising: for each of a plurality of network functions of a network function chain, generating a subgraph, wherein a representation of each of the plurality of network elements is split into two vertexes, and an edge is added between the split two vertexes of the representation of each network element that hosts that network function of the subgraph; ordering the subgraphs according to an order of the plurality of network functions of the network function chain; connecting the ordered subgraphs to form a graph, wherein for each ordered subgraph except the last ordered subgraph, each vertex with an edge in the ordered subgraph being connected with an edge to another vertex with an edge in the next ordered subgraph, each connection including all paths of the network between a pair of network elements represented by the vertexes connected with the edge, and wherein each edge in the graph includes a cost measure; determining vertexes of a representation of a source network element and a representation of a destination network element in the graph; and selecting a path from the vertex of the representation of the source network element to the vertex of the representation of the destination network element in the graph to identify a route through the plurality of network functions of the network function chain, wherein each edge of the path is selected based on at least its cost measure.