<｜begin▁of▁sentence｜>### Instruction:
Imagine you're a sales rep at a tech firm specializing in patent analysis, and your latest product is a sophisticated software tool designed to evaluate the influence of a patent within the industry. Your client is interested in understanding the impact of a particular patent on its predecessors within a specific timeframe—let's say they're keen on assessing patents cited within the last five years. 

Using our software, which has the ability to process patent data represented in a graph format—imagine this data is stored in a file called "patents_graph.gml"—the client wants to generate a Consolidation-Destabilization (CD) index for a chosen patent. This index should reflect the patent's significance based on how it either consolidates or disrupts prior patents (it's predecessors), with importance given to the 'time' attribute each patent node has, as well as a 'weight' attribute if available. The relationships between patents are symbolized by the edges of the graph, akin to citations in research papers.

So, the question your client needs addressing is: How can our software calculate the CD index for a designated patent, taking into account its predecessors but only within the particular timespan they're interested in, such as the aforementioned five-year window? This will help them pinpoint the market stability a patent brings based on its historical connections within the given timeframe. Your challenge is to showcase this feature of our software and demonstrate how it can be customized for such specific analytical needs.
### Response:
from datetime import datetime, timedelta
import networkx as nx

# Create a directed graph
G = nx.DiGraph()

# Define nodes with 'time' and optional 'weight' attributes
nodes = {
    1: {'time': datetime(2015, 1, 1)},
    2: {'time': datetime(2012, 1, 1), 'weight': 4},
    3: {'time': datetime(2010, 1, 1)},
    4: {'time': datetime(2008, 1, 1)},
    5: {'time': datetime(2014, 1, 1)}
}

# Add nodes to the graph
G.add_nodes_from([(n, nodes[n]) for n in nodes])

# Define edges
edges = [(1, 3), (1, 4), (2, 3), (3, 4), (3, 5)]
G.add_edges_from(edges)

delta = timedelta(days=5*365)

# Calculate the CD index for node 3
cd_index_without_weight = nx.cd_index(G, 3, time_delta=delta, time='time')
print('CD index without weight:', cd_index_without_weight)

# Calculate the CD index for node 3 with weight
cd_index_with_weight = nx.cd_index(G, 3, time_delta=delta, time='time', weight='weight')
print('CD index with weight:', cd_index_with_weight)
<|EOT|>
