import uic.view_dataset import util.tree_model from gui.progress import Worker from dataset import Dataset, DatasetHeaderC, Analysis, ExportVariant from util.codec import Codec, FileIn, FileOut, listC, strC, intC, namedtupleC from util.codec_progress import CodecProgress, listCP, oneCP class Subject(NamedTuple): name: str observations: int active_choices: int deferrals: int SubjectC = namedtupleC(Subject, strC, intC, intC, intC) class SubjectNode(util.tree_model.Node): def __init__(self, parent_node, row: int, subject: Subject) -> None: util.tree_model.Node.__init__( self, parent_node, row, fields=subject, child_count=0, ) class RootNode(util.tree_model.RootNode): def __init__(self, subjects: List[Subject]) -> None:
import uic.view_dataset import util.tree_model from gui.progress import Worker from dataset import Dataset, DatasetHeaderC, Analysis, ExportVariant from util.codec import Codec, FileIn, FileOut, listC, strC, intC, \ tupleC, namedtupleC, setC, frozensetC from util.codec_progress import CodecProgress, listCP, oneCP log = logging.getLogger(__name__) class Row(NamedTuple): tuple_size : int garp_menu_tuples : Set[FrozenSet[FrozenSet[int]]] # set of tuples of menus (= alt sets) RowC = namedtupleC(Row, intC, setC(frozensetC(frozensetC(intC)))) class Subject(NamedTuple): name : str rows : List[Row] SubjectC = namedtupleC(Subject, strC, listC(RowC)) class MenuRowNode(util.tree_model.Node): def __init__(self, parent_node, row: int, alternatives : List[str], xs : FrozenSet[FrozenSet[int]]) -> None: util.tree_model.Node.__init__( self, parent_node, row, fields=( '', '', '{' + ','.join(
AltSet = FrozenSet[int] AltSetC = frozensetC(intC) Menu = AltSet MenuC = AltSetC class ChoiceRow(NamedTuple): menu: Menu default: Optional[int] choice: AltSet ChoiceRowC = namedtupleC(ChoiceRow, MenuC, maybe(intC), AltSetC) PackedSubject = NewType('PackedSubject', bytes) PackedSubjectC = bytesC class Subject(NamedTuple): name: str alternatives: List[str] choices: List[ChoiceRow] def csv_set(self, alt_set: Iterable[int]) -> str: return ','.join(self.alternatives[i] for i in sorted(alt_set)) def csv_alt(self, index: Optional[int]) -> Optional[str]: if index is None:
import uic.view_dataset import util.tree_model from util.codec import Codec, FileIn, FileOut, namedtupleC, strC, intC, \ frozensetC, listC, bytesC, tupleC, maybe from util.codec_progress import CodecProgress, listCP, oneCP log = logging.getLogger(__name__) class ChoiceRow_str(NamedTuple): menu: FrozenSet[str] default: Optional[str] choice: FrozenSet[str] ChoiceRow_strC = namedtupleC(ChoiceRow_str, frozensetC(strC), maybe(strC), frozensetC(strC)) class ChoiceRowNode(util.tree_model.Node): def __init__(self, parent_node, row: int, cr: ChoiceRow) -> None: subject = parent_node.subject util.tree_model.Node.__init__( self, parent_node, row, fields=(subject.name, subject.csv_set(cr.menu), subject.csv_alt(cr.default), subject.csv_set(cr.choice)), ) class SubjectNode(util.tree_model.Node):
from util.codec import Codec, FileIn, FileOut, namedtupleC, strC, intC, \ frozensetC, listC, bytesC, tupleC, dictC, setC from util.codec_progress import CodecProgress, listCP, oneCP log = logging.getLogger(__name__) class Row(NamedTuple): cycle_length: int garp: int sarp: int garp_binary_menus: int sarp_binary_menus: int RowC = namedtupleC(Row, intC, intC, intC, intC, intC) class SubjectRaw(NamedTuple): name: str rows: List[Row] warp_pairs: int warp_all: int SubjectRawC = namedtupleC(SubjectRaw, strC, listC(RowC), intC, intC) class Subject(NamedTuple): raw: SubjectRaw
from util.codec_progress import CodecProgress, listCP, oneCP from PyQt5.QtGui import QIcon from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QHeaderView class BoundEstimate(NamedTuple): lower : int upper : int def to_str(self) -> str: if self.lower == self.upper: return str(self.lower) else: return f'{self.lower} ≤ x ≤ {self.upper}' BoundEstimateC = namedtupleC(BoundEstimate, intC, intC) class Violations(NamedTuple): garp : int sarp : int ViolationsC = namedtupleC(Violations, intC, intC) class Subject(NamedTuple): subject_name : str violations : List[Tuple[int, Violations]] # cycle length, counts warp_strict : int warp_nonstrict : int hm_garp : BoundEstimate hm_sarp : BoundEstimate hm_warp_strict : BoundEstimate
Issue = Union[RepeatedMenu, ChoiceNotInMenu, ] IssueC = enumC('Issue', { RepeatedMenu: (setC(intC), ), ChoiceNotInMenu: (setC(intC), intC), }) class Subject(NamedTuple): name: str issues: List[Issue] SubjectC = namedtupleC(Subject, strC, listC(IssueC)) class IssueNode(util.tree_model.Node): def __init__(self, parent_node, row: int, alternatives: List[str], issue: Issue) -> None: if isinstance(issue, RepeatedMenu): fields = ( 'repeated menu', ','.join(alternatives[i] for i in sorted(issue.menu)), '', ) elif isinstance(issue, ChoiceNotInMenu): fields = ( 'choice not in menu', ','.join(alternatives[i] for i in sorted(issue.menu)),
class Penalty(NamedTuple): # both bounds are inclusive lower_bound: int upper_bound: int def __str__(self): return str(self.to_csv()) def to_csv(self) -> Union[int, str]: if self.lower_bound != self.upper_bound: return f'{self.lower_bound-1} < N ≤ {self.upper_bound}' else: return self.upper_bound PenaltyC = namedtupleC(Penalty, intC, intC) class Request(NamedTuple): # type: ignore subjects: List[dataset.PackedSubject] models: Sequence[model.Model] disable_parallelism: bool RequestC = namedtupleC(Request, listC(dataset.PackedSubjectC), listC(ModelC), boolC) InstanceRepr = NewType('InstanceRepr', bytes) InstanceReprC = bytesC
import dataset.budgetary_consistency from core import Core from dataset import Dataset, Analysis, ExportVariant, DatasetHeaderC from dataset.budgetary_consistency import BudgetaryConsistency from typing import Sequence, NamedTuple, List, Dict, Tuple, Iterator, Union, Optional from gui.progress import Worker, Cancelled from util.codec import FileOut, FileIn, namedtupleC, strC, numpyC, listC from util.codec_progress import CodecProgress, listCP, oneCP from PyQt5.QtWidgets import QDialog, QTreeWidgetItem, QHeaderView class Subject(NamedTuple): name : str prices : np.array amounts : np.array SubjectC = namedtupleC(Subject, strC, numpyC(np.float32), numpyC(np.float32)) class RowNode(util.tree_model.Node): def __init__(self, parent_node, row: int, prices: np.array, amounts: np.array) -> None: util.tree_model.Node.__init__( self, parent_node, row, fields=[''] \ + ['%.2f' % p for p in prices] \ + ['%g' % x for x in amounts] \ + ['%.2f' % np.dot(prices, amounts)] ) class SubjectNode(util.tree_model.Node): def __init__(self, parent_node, row: int, subject: Subject) -> None: self.subject = subject util.tree_model.Node.__init__(
MenuGeneratorC = enumC( 'GenMenus', { Exhaustive: (), SampleWithReplacement: (intC, ), Copycat: (PackedSubjectC, ), Binary: (), }) class GenMenus(NamedTuple): generator: MenuGenerator defaults: bool GenMenusC = namedtupleC(GenMenus, MenuGeneratorC, boolC) class Instance(NamedTuple): code: bytes tag: int = 0 class Uniform(NamedTuple): forced_choice: bool multiple_choice: bool tag: int = 1 GenChoices = Union[Instance, Uniform, ]
log = logging.getLogger(__name__) class PreorderParams(NamedTuple): strict: Optional[bool] total: Optional[bool] SIGN = {True: '', False: '¬', None: '?'} def strPP(p) -> str: return '({0}S, {1}T)'.format(SIGN[p.strict], SIGN[p.total]) PreorderParamsC = namedtupleC(PreorderParams, maybe(boolC), maybe(boolC)) class PreorderMaximization(NamedTuple): p: PreorderParams tag: int = 0 class Unattractiveness(NamedTuple): p: PreorderParams tag: int = 1 class UndominatedChoice(NamedTuple): strict: bool tag: int = 2