Exemplo n.º 1
0
def test_04():  #y = 2; y = 2x-6
    ln1 = make_line_eq(make_var('y'), make_const(2.0))
    ln2 = make_line_eq(
        make_var('y'),
        make_plus(make_prod(make_const(2.0), make_pwr('x', 1.0)),
                  make_const(-6.0)))
    print(line_intersection(ln1, ln2))
    print(line_intersection(ln2, ln1))
Exemplo n.º 2
0
def test_11():  #x = 1; y = 0.5x;  y = -3/4x + 3
    ln1 = make_line_eq(make_var('x'), make_const(1.0))
    ln2 = make_line_eq(make_var('y'),
                       make_prod(make_const(0.5), make_pwr('x', 1.0)))
    print(line_intersection(ln1, ln2))
    ln3 = make_line_eq(
        make_var('y'),
        make_plus(make_prod(make_const(-3.0 / 4.0), make_pwr('x', 1.0)),
                  make_const(3.0)))
    print(line_intersection(ln1, ln3))
    print(line_intersection(ln2, ln3))
Exemplo n.º 3
0
def test_09():  #y = 5; y = -x +6
    ln1 = make_line_eq(make_var('y'), make_const(5.0))
    ln2 = make_line_eq(
        make_var('y'),
        make_plus(make_prod(make_const(-1.0), make_pwr('x', 1.0)),
                  make_const(6.0)))
    print(line_intersection(ln1, ln2))
Exemplo n.º 4
0
def test_12():
    ln1 = make_line_eq(make_var('x'), make_const(0.0))
    ln2 = make_line_eq(make_var('y'), make_const(0.0))
    ln3 = make_line_eq(
        make_var('y'),
        make_plus(make_prod(make_const(-4.0 / 3), make_pwr('x', 1.0)),
                  make_const(160.0)))
    ln4 = make_line_eq(
        make_var('y'),
        make_plus(make_prod(make_const(-0.5), make_pwr('x', 1.0)),
                  make_const(120.0)))
    print(ln1)
    print(ln3)
    print(line_intersection(ln1, ln3))
    print(ln2)
    print(ln3)
    print(line_intersection(ln2, ln3))
    print(line_intersection(ln3, ln4))
Exemplo n.º 5
0
def test_07():  #y = -1/5x +10; y = 1/5x + 5
    ln1 = make_line_eq(
        make_var('y'),
        make_plus(make_prod(make_const(-1.0 / 5.0), make_pwr('x', 1.0)),
                  make_const(10.0)))
    ln2 = make_line_eq(
        make_var('y'),
        make_plus(make_prod(make_const(1.0 / 5.0), make_pwr('x', 1.0)),
                  make_const(5.0)))
    print(line_intersection(ln1, ln2))
Exemplo n.º 6
0
def linear_programming_prob1():
    f1 = lambda x, y: 5 * x + 4 * y
    ln1 = make_line_eq(
        make_var('y'),
        make_plus(make_prod(const(-4.0 / 3.0), make_pwr('x', 1.0)),
                  make_const(160)))
    ln2 = make_line_eq(
        make_var('y'),
        make_plus(make_prod(const(-3.0 / 6.0), make_pwr('x', 1.0)),
                  make_const(120)))

    ln3 = make_line_eq(make_var('x'), make_const(0.0))
    ln4 = make_line_eq(make_var('y'), make_const(0.0))

    cp_1 = line_intersection(ln2, ln3)
    cp_2 = line_intersection(ln1, ln2)
    cp_3 = line_intersection(ln1, ln4)

    corner_points = [cp_1, cp_2, cp_3]

    max_xy = maximize_obj_fun(f1, corner_points)
    max_val = f1(max_xy.get_x().get_val(), max_xy.get_y().get_val())
    print(max_xy, max_val)
Exemplo n.º 7
0
def test_03():  #y = -2; y = x +10
    ln1 = make_line_eq(make_var('y'), make_const(-2.0))
    ln2 = make_line_eq(make_var('y'),
                       make_plus(make_pwr('x', 1.0), make_const(10.0)))
    print(line_intersection(ln1, ln2))
    print(line_intersection(ln2, ln1))
Exemplo n.º 8
0
def test_01():
    ln1 = make_line_eq(make_var('y'), make_const(1.0))
    ln2 = make_line_eq(make_var('x'), make_const(1.0))
    assert is_const_line(ln1)
    assert is_const_line(ln2)
    print(line_intersection(ln1, ln2))