Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nextmv.Model syntax #87

Merged
merged 1 commit into from
Dec 10, 2024
Merged

Conversation

sebastian-quintero
Copy link
Member

@sebastian-quintero sebastian-quintero commented Dec 9, 2024

The changes appear to be a lot, but really I am changing all python apps to, instead of using this:

    output = solve(input, options)

We now use this:

    model = DecisionModel()
    output = model.solve(input)


class DecisionModel(nextmv.Model):
    def solve(self, input: nextmv.Input) -> nextmv.Output:
        """Solves the given problem and returns the solution."""

We are basically trading the use of the solve function in favor of the DecisionModel declaration with the solve method. Inside the method, where we were doing options.xyz we now do input.options.xyz.

The changes to indentation is what makes this PR bloat up.

Copy link
Member

@merschformann merschformann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I skimmed the changes and all looks good. Thanks for the work! 🤗

Comment on lines +240 to +254
def validate_skills(input: nextmv.Input) -> Any:
"""Check that each project skill and each worker skill have a skill pair."""

for project in input.data["projects"]:
for skill in project["required_skills"]:
if not any(skill in worker["skills"] for worker in input.data["workers"]):
return errorStatusOutput("input_skill_error", input.options)
return error_status_output("input_skill_error", input.options)
for worker in input.data["workers"]:
for skill in worker["skills"]:
if not any(skill in project["required_skills"] for project in input.data["projects"]):
return errorStatusOutput("input_skill_error", input.options)
return error_status_output("input_skill_error", input.options)
return None


def errorStatusOutput(status: str, options: nextmv.Options) -> nextmv.Output:
def error_status_output(status: str, options: nextmv.Options) -> nextmv.Output:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for aligning the style along the way. ❤️

@sebastian-quintero sebastian-quintero merged commit 7f62ad2 into develop Dec 10, 2024
38 checks passed
@sebastian-quintero sebastian-quintero deleted the feature/python-nextmv-model branch December 10, 2024 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants