Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
from_model.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# Copyright 2010-2025 Google LLC
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15"""Utilities for finding the model associated with a variable/constraint etc.
16
17This file is an implementation detail and not part of the MathOpt public API.
18"""
19
20from typing import Protocol
21from ortools.math_opt.python.elemental import elemental
22
23
24class FromModel(Protocol):
25
26 __slots__ = ()
27
28 @property
29 def elemental(self) -> elemental.Elemental: ...
30
31
32def model_is_same(e1: FromModel, e2: FromModel) -> None:
33 if e1.elemental is not e2.elemental:
34 raise ValueError(
35 f"Expected two elements from the same model, but observed {e1} from"
36 f" model named: '{e1.elemental.model_name!r}', and {e2} from model"
37 f" named: '{e2.elemental.model_name!r}'."
38 )
None model_is_same(FromModel e1, FromModel e2)
Definition from_model.py:32