Platypus NSGA-II, optimales Problem mit variabler DruckvariablenPython

Python-Programme
Anonymous
 Platypus NSGA-II, optimales Problem mit variabler Druckvariablen

Post by Anonymous »

Ich stieß auf ein Problem, wenn ich versuche, die "besten" Entscheidungsvariablenwerte basierend auf einem bestimmten Fall zu drucken (dass das einzige Ziel weniger als 1 ist). Ich verwende den NSGA-II-Algorithmus aus Platypus. Wert): < /p>
import streamlit as st
import matplotlib.pyplot as plt
from platypus import NSGAII, Problem, Integer

st.title("Pareto Front using NSGA-II (Platypus)")

# Define problem
problem = Problem(1, 2)
problem.types[0] = Integer(-10, 10)
problem.function = lambda x: [x[0]**2, (x[0]-2)**2]

# Run NSGA-II
algorithm = NSGAII(problem)
algorithm.run(10000)

# Extract solutions
solutions = algorithm.result
f1 = [s.objectives[0] for s in solutions]
f2 = [s.objectives[1] for s in solutions]

# Filter: objective2 < 1
filtered = [s for s in solutions if s.objectives[1] < 1]

if filtered:
# Find solution with lowest objective1
best = min(filtered, key=lambda s: s.objectives[0])
st.subheader("Best solution with f2 < 1")
st.write(f"Decision variables: {best.variables}")
st.write(f"Objectives: f1={best.objectives[0]:.4f}, f2={best.objectives[1]:.4f}")

# Plot
fig, ax = plt.subplots()
ax.scatter(f1, f2, c="blue", s=10, alpha=0.5, label="All Solutions")
ax.scatter(
[best.objectives[0]], [best.objectives[1]],
c="red", s=80, label="Best (f2 < 1)"
)
ax.set_xlabel("Objective 1 (x^2)")
ax.set_ylabel("Objective 2 ((x-2)^2)")
ax.set_title("Pareto Front (NSGA-II)")
ax.legend()
ax.grid(True)

st.pyplot(fig)

else:
st.warning("No solutions found with f2 < 1")
< /code>
Ich habe versucht, ein LLM aufzufordern, konnte dies aber nicht zum Laufen bringen. Gibt es etwas Einfaches, das mir fehlt?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post