Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions desdeo/api/models/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,15 @@ class RepresentativeNonDominatedSolutions(RepresentativeSolutionSetBase, SQLMode
metadata_id: int | None = Field(foreign_key="problemmetadatadb.id", default=None)
metadata_type: str = "representative_non_dominated_solutions"

solution_data: dict[str, list[float]] = Field(sa_column=Column(JSON))
ideal: dict[str, float] = Field(sa_column=Column(JSON))
nadir: dict[str, float] = Field(sa_column=Column(JSON))

solution_data: dict[str, list[float]] = Field(sa_column=Column(JSON),
description="The non-dominated solutions. It is assumed that columns "
"exist for each variable and objective function. For functions, the "
"`_min` variant should be present, and any tensor variables should be "
"unrolled.")
ideal: dict[str, float] = Field(sa_column=Column(JSON),
description="The ideal objective function values of the representative set.")
nadir: dict[str, float] = Field(sa_column=Column(JSON),
description="The nadir objective function values of the representative set.")

metadata_instance: "ProblemMetaDataDB" = Relationship(back_populates="representative_nd_metadata")

Expand Down
26 changes: 10 additions & 16 deletions desdeo/api/routers/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,13 @@ def select_solver(
response_model=RepresentativeSolutionSetInfo
)
def add_representative_solution_set(
payload: RepresentativeSolutionSetRequest,
context: Annotated[SessionContext, Depends(get_session_context_without_request)],
request: RepresentativeSolutionSetRequest,
context: Annotated[SessionContext, Depends(get_session_context)],
):
"""Add a new representative solution set as metadata to a problem.

Args:
payload (RepresentativeSolutionSetRequest): The JSON body containing the
request (RepresentativeSolutionSetRequest): The JSON body containing the
details of the representative solution set (name, description, solution data, ideal, nadir).
context (SessionContext): The session context providing the current user and database session.

Expand All @@ -345,17 +345,11 @@ def add_representative_solution_set(
Returns:
dict: Confirmation message.
"""
user = context.user
db_session: Session = context.db_session
problem_db = context.problem_db

# Fetch the problem
problem_db = db_session.get(ProblemDB, payload.problem_id)
if problem_db is None:
raise HTTPException(status_code=404, detail=f"Problem with ID {payload.problem_id} not found.")

# Check the user
if user.id != problem_db.user_id:
raise HTTPException(status_code=401, detail="Unauthorized user.")
raise HTTPException(status_code=500, detail="Problem context missing.")

# Ensure metadata object exists
if problem_db.problem_metadata is None:
Expand All @@ -369,11 +363,11 @@ def add_representative_solution_set(
# Add new representative solution set
repr_metadata = RepresentativeNonDominatedSolutions(
metadata_id=problem_metadata.id,
name=payload.name,
description=payload.description,
solution_data=payload.solution_data,
ideal=payload.ideal,
nadir=payload.nadir,
name=request.name,
description=request.description,
solution_data=request.solution_data,
ideal=request.ideal,
nadir=request.nadir,
metadata_instance=problem_metadata,
)

Expand Down
3 changes: 2 additions & 1 deletion desdeo/api/routers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
StateDB,
User,
)
from desdeo.api.models.representative_solution import RepresentativeSolutionSetRequest
from desdeo.api.routers.user_authentication import get_current_user

RequestType = RPMSolveRequest | ENautilusStepRequest
RequestType = RPMSolveRequest | ENautilusStepRequest | RepresentativeSolutionSetRequest


def fetch_interactive_session(user: User, request: RequestType, session: Session) -> InteractiveSessionDB | None:
Expand Down
Loading