Пример #1
0
def convert_task(base_system: RestrictionSystem, divider: ObjectiveFunction):
    if len(base_system.__objective_function__.coefficients) != len(divider.coefficients):
        return None

    base_system = base_system.to_canonical_form()
    divider = copy.deepcopy(divider)
    new_variable_count  = len(base_system.__objective_function__.coefficients)
    new_variable_count -= len(divider.coefficients)
    for _ in range(new_variable_count):
        divider.coefficients.append(0)

    system = RestrictionSystem()
    function = system.__objective_function__
    for _ in range(len(divider.coefficients)):
        system.add_variable(Variable())
    function.purpose = Purpose.MAX
    function.coefficients = copy.deepcopy(base_system.__objective_function__.coefficients)
    function.coefficients.append(base_system.__objective_function__.free_member)
    function.free_member = 0

    for base_row in base_system.__rows__:
        row = system.create_restriction()
        row.coefficients = copy.deepcopy(base_row.coefficients)
        row.coefficients.append(-base_row.free_member)
        row.free_member = 0

    row = system.create_restriction()
    row.coefficients = copy.deepcopy(divider.coefficients)
    row.coefficients.append(divider.free_member)
    row.free_member = 1

    return system
Пример #2
0
def create_restriction_system(table: SimplexTable):
    system = RestrictionSystem()
    for _ in range(len(table.__objective_function__.coefficients)):
        system.add_variable(Variable())

    for row in table.__rows__:
        system_row = system.create_restriction()
        system_row.free_member = row.free_member
        system_row.coefficients = copy.deepcopy(row.coefficients)
        system_row.sign = Sign.EQUALS
    function = system.__objective_function__
    function.coefficients = [
        -v for v in table.__objective_function__.coefficients
    ]
    function.free_member = -table.__objective_function__.free_member
    function.purpose = Purpose.MAX

    return system
Пример #3
0
        queue += Gomori.create_branches(elem, req_variables)
    html += "Лучшая таблица - это:<br>"
    html += best_table.to_html() + "<br><br>"
    return html


if __name__ == "__main__":
    app = QApplication([])
    widget = MainWindow()
    widget.show()

    system = RestrictionSystem()
    function = system.__objective_function__
    for _ in range(5):
        system.add_variable(Variable())

    # function.free_member = 0
    # function.coefficients = [3, 1, 0, 0, -1]
    # function.purpose = Purpose.MAX

    # function.free_member = 6
    # function.coefficients = [0, 5, 0, 0, 0]
    # function.purpose = Purpose.MAX

    # row = system.create_restriction()
    # row.coefficients = [7, 5, 1, 0, 0]
    # row.free_member = 28

    # row = system.create_restriction()
    # row.coefficients = [4, -6, 0, 3, 0]