Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yomichi committed Mar 25, 2024
1 parent 5c47712 commit 99c78ec
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions src/py2dmat/util/limitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,31 @@

import numpy as np

import py2dmat

# for type hints
from pathlib import Path
from typing import List, Optional, Dict

class LimitationBase(metaclass=ABCMeta):
@abstractmethod
def __init__ (self, a: np.ndarray, b: np.ndarray, is_limitary: bool):
def __init__(self, a: np.ndarray, b: np.ndarray, is_limitary: bool):

self.islimitary = is_limitary
if self.islimitary:
self.a = a
self.b = b
self.minusb = -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: np.ndarray, b: np.ndarray, is_limitary: bool):
def __init__(self, a: np.ndarray, b: np.ndarray, is_limitary: bool):
super().__init__(a, b, is_limitary)

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)
if self.islimitary:
Ax = np.einsum("ij,j->i", self.a, x)
judge_result = all(Ax > self.minusb)
else:
judge_result = True
return judge_result

0 comments on commit 99c78ec

Please sign in to comment.