# クラスタリング結果の表示 for i, c inenumerate(communities): print("Cluster ", i+1, ": ", c)
# クラスタリング結果をグラフに反映 color_map = [] for node in G: for i, c inenumerate(communities): if node in c: color_map.append(i) nx.draw(G, pos, node_color=color_map, with_labels=True) plt.show()
# 結果の出力 print("Status:", LpStatus[status]) print("Optimal Solution:") for var in prob.variables(): print(var.name, "=", var.varValue) print("Total Cost of Ingredients = ", value(prob.objective))
# ①問題を初期化 problem = pulp.LpProblem("マーケティング最適化問題", pulp.LpMaximize)
# ②変数を定義 a = pulp.LpVariable("Aの広告費用", lowBound=0) b = pulp.LpVariable("Bの広告費用", lowBound=0) c = pulp.LpVariable("Cの広告費用", lowBound=0)
# ③目的関数を定義 problem += 300*a + 200*b + 150*c, "利益の合計"
# ④制約条件を定義 problem += a + b + c <= 10000, "広告予算の合計" problem += a <= 2000, "Aの広告費用の上限" problem += b <= 1500, "Bの広告費用の上限" problem += c <= 1000, "Cの広告費用の上限"