-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Using the coefficients co_a and co_b, you can make it search only the range that meets the following constraint formula. --- co_a[1,1]*x_[1] + co_a[1,2]*x_[2] + ... + co_a[1,n]*x_[n] + co_b[1] > 0 co_a[2,1]*x_[1] + co_a[2,2]*x_[2] + ... + co_a[2,n]*x_[n] + co_b[2] > 0 ... co_a[m,1]*x_[1] + co_a[m,2]*x_[2] + ... + co_a[m,n]*x_[n] + co_b[m] > 0 --- - co_a and co_b can be defined in option [runner.limitation] in the toml file. - When setting constraint formulas, both co_a and co_b must be set in the toml file. - If neither co_a nor co_b are set in the toml file, the calculation can be performed without constraint formulas. - If the initial_list set in [algorithm.param] does not fit the constraint formulas, an error occurs. - If initial_list is not set in [algorithm.param], then initial coordinates that fit the constraint formulas are created.
- Loading branch information
1 parent
da948bc
commit 168da7d
Showing
3 changed files
with
137 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from abc import ABCMeta, abstractmethod | ||
|
||
import numpy as np | ||
|
||
import py2dmat | ||
|
||
# for type hints | ||
from pathlib import Path | ||
from typing import List, Optional, TYPE_CHECKING, Dict, Tuple | ||
|
||
class LimitationBase(metaclass=ABCMeta): | ||
@abstractmethod | ||
def __init__ (self, a: Optional[np.ndarray] = None, | ||
b: Optional[np.ndarray] = None): | ||
if (a is not None) or (b is not None): | ||
if a is None: | ||
msg = "ERROR: b is defined but a is not." | ||
raise RuntimeError(msg) | ||
if b is None: | ||
msg = "ERROR: a is defined but b is not." | ||
raise RuntimeError(msg) | ||
if (a is None) and (b is None): | ||
self.islimitary = False | ||
else: | ||
self.islimitary = True | ||
self.a = a | ||
self.b = b | ||
self.n_formura = a.shape[0] | ||
self.ndim = a.shape[1] | ||
|
||
@abstractmethod | ||
def judge(self, x: np.ndarray) -> bool: | ||
pass | ||
|
||
class Inequality(LimitationBase): | ||
def __init__ (self, a: Optional[np.ndarray] = None, | ||
b: Optional[np.ndarray] = None): | ||
super().__init__(a, b) | ||
|
||
def judge(self, x: np.ndarray) -> bool: | ||
if self.islimitary : | ||
judge_formula = [] | ||
for formula_index in range(self.n_formura): | ||
value_formula = 0 | ||
for dim_index in range(self.ndim): | ||
value_formula += self.a[formula_index, dim_index]*x[dim_index] | ||
value_formula += self.b[formula_index] | ||
judge_formula.append(value_formula>0) | ||
judge_result = all(judge_formula) | ||
else: | ||
judge_result = True | ||
return judge_result |