<｜begin▁of▁sentence｜>### Instruction:
Given a complete weighted undirected graph with edge set [('A', 'B', 3), ('A', 'C', 17), ('A', 'D', 14), ('B', 'A', 3), ('B', 'C', 12), ('B', 'D', 16), ('C', 'A', 13), ('C', 'B', 12), ('C', 'D', 4), ('D', 'A', 14), ('D', 'B', 15), ('D', 'C', 2)], how can you use NetworkX to find a greedy approximation for the Traveling Salesman Problem (TSP) starting at node 'D', and what is the total cost of the resulting cycle?
### Response:
import networkx as nx
from networkx.algorithms import approximation as approx

# Create a complete weighted undirected graph
G = nx.Graph()
G.add_weighted_edges_from([
    ('A', 'B', 3), ('A', 'C', 17), ('A', 'D', 14),
    ('B', 'A', 3), ('B', 'C', 12), ('B', 'D', 16),
    ('C', 'A', 13), ('C', 'B', 12), ('C', 'D', 4),
    ('D', 'A', 14), ('D', 'B', 15), ('D', 'C', 2)
])

# Use the greedy algorithm to approximate the TSP solution
# Starting at node 'D'
cycle = approx.greedy_tsp(G, source='D')

# Calculate the total cost of the cycle
cost = sum(G[n][nbr]['weight'] for n, nbr in nx.utils.pairwise(cycle))

# Output the cycle and its cost
print('Cycle:', cycle)
print('Cost:', cost)
<|EOT|>
