Repository navigation
auto_math_constraints_duality_and_shadow_prices_5
github-actions[bot] edited this page Nov 14, 2025
·
1 revision
def plot_constraint_landscape(A, b, x_history, constraint_names):
"""2D constraint view."""
fig, ax = plt.subplots(figsize=(10, 8))
for i, name in enumerate(constraint_names):
if A.shape[1] == 2:
x_line = np.linspace(0, b[i] / A[i, 0], 100)
y_line = (b[i] - A[i, 0] * x_line) / A[i, 1]
ax.plot(x_line, y_line, label=f'{name}', linewidth=2 if i==0 else 1)
x_hist = np.array(x_history)
ax.plot(x_hist[:, 0], x_hist[:, 1], 'ko-', alpha=0.5, label='Path')
ax.plot(x_hist[-1, 0], x_hist[-1, 1], 'r*', markersize=15, label='Optimum')
ax.set_xlabel('Dim 1')
ax.set_ylabel('Dim 2')
ax.legend()
ax.grid(alpha=0.3)
plt.title('Constraints with Path')
plt.savefig('landscape.png', dpi=150)
print("Saved to landscape.png")
# Example
plot_constraint_landscape(A, b, [x0, x_feas, x_opt], ['Cost', 'Time'])