This commit is contained in:
2
main.tex
2
main.tex
@@ -343,7 +343,7 @@ Can we show that the gap is 0 or much smaller than 2?
|
|||||||
\begin{enumerate}
|
\begin{enumerate}
|
||||||
\item One cannot do better than $b\lambda^*$ for general costs.
|
\item One cannot do better than $b\lambda^*$ for general costs.
|
||||||
There are examples (a 4-vertex path with parallel edges) where the gap is almost $b\lambda^*$.\footnote{see \url{https://gitea.talldoor.uk/sxlxc/edge_conn_interdiction/src/branch/master/gap.py}}
|
There are examples (a 4-vertex path with parallel edges) where the gap is almost $b\lambda^*$.\footnote{see \url{https://gitea.talldoor.uk/sxlxc/edge_conn_interdiction/src/branch/master/gap.py}}
|
||||||
\item Unit cost. We can assume WLOG that $|C^*|>b$ and that $F^*$ is the set of $b$ edges in $C^*$ with largest weights. By the complementary slackness condition, $(C^{LD},F^{LD})$ is optimal for connectivity interdiction IP. Thus we can see the gap is $1$.
|
\item Unit cost. There is still a gap between $L(\lambda^*)$ and $w(C^*\setminus F^*)$.\footnote{see \url{https://gitea.talldoor.uk/sxlxc/edge_conn_interdiction/src/branch/master/plot.py}}
|
||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
|
||||||
\end{remark}
|
\end{remark}
|
||||||
|
|||||||
62
plot.py
Normal file
62
plot.py
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
|
||||||
|
def plot_linear_functions(list1, list2, list3, b, x_range=(0, 10)):
|
||||||
|
"""
|
||||||
|
Plots linear functions y = Cx + D where:
|
||||||
|
C = b - k (k elements removed)
|
||||||
|
D = sum of remaining elements
|
||||||
|
k ranges from 0 to b.
|
||||||
|
"""
|
||||||
|
datasets = [list1, list2, list3]
|
||||||
|
# Distinct colors for the 3 sets
|
||||||
|
colors = ['#E63946', '#457B9D', '#1D3557']
|
||||||
|
labels = ['List 1', 'List 2', 'List 3']
|
||||||
|
|
||||||
|
plt.figure(figsize=(12, 8))
|
||||||
|
x = np.linspace(x_range[0], x_range[1], 100)
|
||||||
|
|
||||||
|
for i, current_list in enumerate(datasets):
|
||||||
|
# Sort descending so the first k elements are the 'top k'
|
||||||
|
sorted_list = sorted(current_list, reverse=True)
|
||||||
|
|
||||||
|
for k in range(len(sorted_list) + 1):
|
||||||
|
# C is the fixed number b minus the number of elements removed
|
||||||
|
C = k-b
|
||||||
|
|
||||||
|
# Remove top k elements (if k > list length, remaining is empty)
|
||||||
|
remaining = sorted_list[k:] if k < len(sorted_list) else []
|
||||||
|
|
||||||
|
# D is the sum of the remaining elements
|
||||||
|
D = sum(remaining)
|
||||||
|
|
||||||
|
y = C * x + D
|
||||||
|
|
||||||
|
# Plot the line; label only once per list for a clean legend
|
||||||
|
line_label = labels[i] if k == 0 else ""
|
||||||
|
if C == 0:
|
||||||
|
plt.plot(x, y, color=colors[i], alpha=1,
|
||||||
|
label=line_label, linestyle='-')
|
||||||
|
else:
|
||||||
|
plt.plot(x, y, color=colors[i], alpha=0.6,
|
||||||
|
label=line_label, linestyle='--')
|
||||||
|
|
||||||
|
plt.title(
|
||||||
|
f"2D Linear Functions: $y = (b-k)x + sum(rem)$ for $0 ≤ k ≤ b$ ($b={b}$)")
|
||||||
|
plt.xlabel("x")
|
||||||
|
plt.ylabel("y")
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.7)
|
||||||
|
plt.legend()
|
||||||
|
plt.savefig('linear_plot.png')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
|
# --- Example Usage ---
|
||||||
|
# Replace these with your actual lists and b value
|
||||||
|
L1 = [45, 14, 7, 7, 4, 2]
|
||||||
|
L2 = [20, 15, 10, 5, 4, 2]
|
||||||
|
L3 = [5, 5, 5, 5, 5, 5]
|
||||||
|
fixed_b = 2
|
||||||
|
|
||||||
|
plot_linear_functions(L1, L2, L3, fixed_b)
|
||||||
Reference in New Issue
Block a user