Skip to content
Snippets Groups Projects

Introduce Chars

Merged Björn Ludwig requested to merge introduce_chars into main
1 file
+ 1
1
Compare changes
  • Side-by-side
  • Inline
@@ -12,8 +12,9 @@ $ python -m ilp_keyboard_layout_optimization.optimize
We might add command line parameters at a later time. For now please edit the main
function at the very bottom of this file to change inputs.
"""
from ilp_keyboard_layout_optimization.data_aquisition.chars import Chars
from ilp_keyboard_layout_optimization.ilp import KeyboardOptimization
from ilp_keyboard_layout_optimization.types import LinCosts, QuadCosts
from ilp_keyboard_layout_optimization.type_aliases import LinCosts, QuadCosts
def prepare_costs(
@@ -33,48 +34,48 @@ def prepare_costs(
"""
_linear_costs = {}
_quad_costs = {}
for (char, loc) in optimization_problem.char_key_assigns_keys:
for (char, pos) in optimization_problem.char_key_assigns_keys:
if (
(char == "u" and loc == "left_pinky_home")
or (char == "n" and loc == "right_index_home")
or (char == "r" and loc == "right_middle_home")
or (char == "t" and loc == "right_ring_home")
or (char == "d" and loc == "right_pinky_home")
(char == "u" and pos == "left_pinky_home")
or (char == "n" and pos == "right_index_home")
or (char == "r" and pos == "right_middle_home")
or (char == "t" and pos == "right_ring_home")
or (char == "d" and pos == "right_pinky_home")
):
_linear_costs[char, loc] = 0.0
_linear_costs[char, pos] = 0.0
continue
_linear_costs[char, loc] = 1.0
_linear_costs[char, pos] = 1.0
for (char, char_2, loc, loc_2) in optimization_problem.quad_char_key_assigns_keys:
for (char, char_2, pos, pos_2) in optimization_problem.quad_char_key_assigns_keys:
if (
(
char == "u"
and loc == "left_pinky_home"
and pos == "left_pinky_home"
and char_2 == "i"
and loc_2 == "left_middle_home"
and pos_2 == "left_middle_home"
)
or (
char == "i"
and loc == "left_middle_home"
and pos == "left_middle_home"
and char_2 == "a"
and loc_2 == "left_index_home"
and pos_2 == "left_index_home"
)
or (
char == "a"
and loc == "left_index_home"
and pos == "left_index_home"
and char_2 == "e"
and loc_2 == "left_ring_home"
and pos_2 == "left_ring_home"
)
):
_quad_costs[char, char_2, loc, loc_2] = 0.0
_quad_costs[char, char_2, pos, pos_2] = 0.0
continue
_quad_costs[char, char_2, loc, loc_2] = 1.0
_quad_costs[char, char_2, pos, pos_2] = 1.0
return _linear_costs, _quad_costs
if __name__ == "__main__":
test_chars = ("a", "e", "i", "u", "n", "r", "t", "d")
test_locs = (
test_chars = Chars(("a", "e", "i", "u", "n", "r", "t", "d"))
test_poss = (
"left_pinky_home",
"left_ring_home",
"left_middle_home",
@@ -84,7 +85,7 @@ if __name__ == "__main__":
"right_ring_home",
"right_pinky_home",
)
optimization_model = KeyboardOptimization(test_chars, test_locs)
optimization_model = KeyboardOptimization(test_chars, test_poss)
linear_costs, quad_costs = prepare_costs(optimization_model)
optimization_model.set_up_model(linear_costs, quad_costs)
optimization_model.solve()
Loading