Skip to content
Snippets Groups Projects
Unverified Commit 96ac13b9 authored by Björn Ludwig's avatar Björn Ludwig
Browse files

refactor(type_aliases): rename some type aliases, the module itself and include all in __all__

parent fb813af0
No related branches found
No related tags found
1 merge request!1Introduce Chars
This commit is part of merge request !1. Comments created here will be created in the context of that merge request.
......@@ -2,9 +2,11 @@
__all__ = ["Chars"]
from typing import Optional, Union
import string
from itertools import product
from typing import Optional, Tuple, Union
from src.ilp_keyboard_layout_optimization.type_aliases import CharTuple
from ..type_aliases import Bigram, CharTuple
class Chars:
......
......@@ -14,6 +14,17 @@ from .type_aliases import (
)
from pyscipopt import Model, quicksum
from .data_aquisition.chars import Chars
from .type_aliases import (
CharPosPair,
CharPosQuadruple,
LinCosts,
LinVars,
PosTuple,
QuadCosts,
QuadVars,
)
class KeyboardOptimization:
"""Instances of this class represent instances of the keyboard layout QAP
......@@ -179,12 +190,12 @@ class KeyboardOptimization:
print(f"{str(solution_assignments)}")
@property
def char_key_assigns_keys(self) -> Iterable[CharKeyPair]:
def char_key_assigns_keys(self) -> Iterable[CharPosPair]:
"""An iterator for the pairs of (special) characters and corresponding keys"""
return product(self.chars, self.keys)
@property
def quad_char_key_assigns_keys(self) -> Iterable[CharKeyQuadruple]:
def quad_char_key_assigns_keys(self) -> Iterable[CharPosQuadruple]:
"""An iterator for quadruples of character pairs and corresponding key pairs"""
flattened_tuple_of_quads = chain.from_iterable(
chain.from_iterable(
......
"""This module contains custom types for type hints and thus more convenient coding"""
"""This module contains type aliases for type hints and thus more convenient coding"""
__all__ = [
"CharKeyPair",
"CharKeyQuadruple",
"CharTuple",
"Bigram",
"Char",
"CharPosPair",
"CharPosQuadruple",
"CharSet",
"KeyTuple",
"CharTuple",
"LinCosts",
"LinVars",
"Pos",
"PosPair",
"PosTuple",
"QuadCosts",
"QuadVars",
]
Char = str
"""A (special) character"""
Key = str
"""A key"""
CharKeyPair = tuple[Char, Key]
"""A pair of a (special) character and a key"""
Bigram = tuple[Char, Char]
"""A tuple of two (special) characters"""
KeyPair = tuple[Key, Key]
"""A tuple of two keys"""
Pos = str
"""A position"""
CharPosPair = tuple[Char, Pos]
"""A pair of a (special) character and a position"""
Bigram = str
"""A length-two string of (special) characters"""
PosPair = tuple[Pos, Pos]
"""A tuple of two positions"""
CharTuple = tuple[Char, ...]
"""A tuple of several (special) characters"""
CharSet = set[Char]
"""A set of several (special) characters"""
KeyTuple = tuple[Key, ...]
"""A tuple of several keys"""
LinCosts = dict[CharKeyPair, float]
PosTuple = tuple[Pos, ...]
"""A tuple of several positions"""
LinCosts = dict[CharPosPair, float]
"""A dictionary assigning costs to (special) character bigrams"""
CharKeyQuadruple = tuple[Char, Key, Char, Key]
"""A four-tuple: (special) character, key, another (special) character, another key"""
QuadCosts = dict[CharKeyQuadruple, float]
"""A dictionary assigning costs to (special) character, key quadruples"""
LinVars = dict[CharKeyPair, bool]
"""A dictionary of binary decisions of assigning (special) characters to keys"""
QuadVars = dict[CharKeyQuadruple, bool]
"""A dictionary of binary decisions of assigning two (special) characters to two keys"""
CharPosQuadruple = tuple[Char, Char, Pos, Pos]
"""A four-tuple: two (special) characters and their respective positions"""
QuadCosts = dict[CharPosQuadruple, float]
"""A dictionary assigning costs to (special) character, position quadruples"""
LinVars = dict[CharPosPair, bool]
"""A dictionary of binary decisions of assigning (special) characters to positions"""
QuadVars = dict[CharPosQuadruple, bool]
"""A dictionary of binary vars assigning two (special) characters to two positions"""
from ilp_keyboard_layout_optimization.costs import FreqTuple
from ilp_keyboard_layout_optimization.types import (
from ilp_keyboard_layout_optimization.type_aliases import (
Bigram,
Char,
CharKeyPair,
CharKeyQuadruple,
CharPosPair,
CharPosQuadruple,
CharTuple,
Key,
KeyPair,
KeyTuple,
Pos,
PosPair,
PosTuple,
LinCosts,
LinVars,
QuadCosts,
......@@ -25,23 +25,23 @@ def test_char():
def test_key():
assert Key == str
assert Pos == str
def test_char_key_pair():
assert CharKeyPair == tuple[Char, Key]
assert CharPosPair == tuple[Char, Pos]
def test_bigram():
assert Bigram == tuple[Char, Char]
assert Bigram == str
def test_pos_pair():
assert KeyPair == tuple[Key, Key]
assert PosPair == tuple[Pos, Pos]
def test_lin_costs():
assert LinCosts == dict[CharKeyPair, float]
assert LinCosts == dict[CharPosPair, float]
def test_char_tuple():
......@@ -49,20 +49,20 @@ def test_char_tuple():
def test_pos_tuple():
assert KeyTuple == tuple[Key, ...]
assert PosTuple == tuple[Pos, ...]
def test_lin_vars():
assert LinVars == dict[CharKeyPair, bool]
assert LinVars == dict[CharPosPair, bool]
def test_quad_pos_quadruple():
assert CharKeyQuadruple == tuple[Char, Key, Char, Key]
assert CharPosQuadruple == tuple[Char, Pos, Char, Pos]
def test_quad_costs():
assert QuadCosts == dict[CharKeyQuadruple, float]
assert QuadCosts == dict[CharPosQuadruple, float]
def test_quad_vars():
assert QuadVars == dict[CharKeyQuadruple, bool]
assert QuadVars == dict[CharPosQuadruple, bool]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment