Example #1
0
    def parse(self, path):

        files = self.get_files(path)
        for fpath in files:
            plain = Plain(fpath)
            plain.parse(self.pdf)

        self.create_pdf()
Example #2
0
    def compute_rref(self):
        tf = self.compute_triangular_form()

        #num_variable = tf.dimension;
        num_equation = len(tf)
        row = 0
        pivot_col = 0
        pivot_coe = 0
        #主元系数

        while (row < num_equation):
            #寻找主元
            try:
                pivot_col = Plain.first_nonzero_index(tf[row].normal_vector)
                #获取主元所在列
                pivot_coe = tf[row][pivot_col]
            except Exception as e:
                if str(e) == tf[row].NO_NONZERO_ELTS_FOUND_MSG:  #该列无主元
                    if (not MyDecimal(
                            tf[row].constant_term).is_near_zero()):  #检查是否为0=k
                        tf[row].constant_term = 1
                        #更改为0=1
                    pivot_coe = 0
                else:
                    raise e

            #处理第row行,将主元系数化为1
            if (not MyDecimal(pivot_coe).is_near_zero()):  #之前检查是否有主元?
                tf.multiply_coefficient_and_row(1 / pivot_coe, row)
                #将第row行之前的行中与第row行主元列同列的系数全部清0
                tf.SetTheSpecifiedColOfPreviousRowToZero(row, pivot_col)

            row += 1

        return tf
Example #3
0
# -*- coding=utf-8 -*-

from plain import Plain

if __name__ == "__main__":
	app         = Plain()
	app.watch_md()
	app.run_server()
Example #4
0
def test3():  #线性方程组化简为行简化阶梯方程组
    p1 = Plain(normal_vector=Vector(['1', '1', '1']), constant_term='1')
    p2 = Plain(normal_vector=Vector(['0', '1', '1']), constant_term='2')
    s = LinearSystem([p1, p2])
    r = s.compute_rref()
    if not (r[0] == Plain(normal_vector=Vector(['1', '0', '0']),
                          constant_term='-1') and r[1] == p2):
        print('test case 1 failed')
    else:
        print('test case 1 successed')
        LinearSystem_print(s, '原始方程')
        LinearSystem_print(r, '行简化阶梯化后方程')

    p1 = Plain(normal_vector=Vector(['1', '1', '1']), constant_term='1')
    p2 = Plain(normal_vector=Vector(['1', '1', '1']), constant_term='2')
    s = LinearSystem([p1, p2])
    r = s.compute_rref()
    if not (r[0] == p1 and r[1] == Plain(constant_term='1')):
        print('test case 2 failed')
    else:
        print('test case 2 successed')
        LinearSystem_print(s, '原始方程')
        LinearSystem_print(r, '行简化阶梯化后方程')

    p1 = Plain(normal_vector=Vector(['1', '1', '1']), constant_term='1')
    p2 = Plain(normal_vector=Vector(['0', '1', '0']), constant_term='2')
    p3 = Plain(normal_vector=Vector(['1', '1', '-1']), constant_term='3')
    p4 = Plain(normal_vector=Vector(['1', '0', '-2']), constant_term='2')
    s = LinearSystem([p1, p2, p3, p4])
    r = s.compute_rref()
    if not (r[0] == Plain(normal_vector=Vector(['1', '0', '0']),
                          constant_term='0') and r[1] == p2
            and r[2] == Plain(normal_vector=Vector(['0', '0', '-2']),
                              constant_term='2') and r[3] == Plain()):
        print('test case 3 failed')
    else:
        print('test case 3 successed')
        LinearSystem_print(s, '原始方程')
        LinearSystem_print(r, '行简化阶梯化后方程')

    p1 = Plain(normal_vector=Vector(['0', '1', '1']), constant_term='1')
    p2 = Plain(normal_vector=Vector(['1', '-1', '1']), constant_term='2')
    p3 = Plain(normal_vector=Vector(['1', '2', '-5']), constant_term='3')
    s = LinearSystem([p1, p2, p3])
    r = s.compute_rref()
    if not (r[0] == Plain(normal_vector=Vector(['1', '0', '0']),
                          constant_term=Decimal('23') / Decimal('9'))
            and r[1] == Plain(normal_vector=Vector(['0', '1', '0']),
                              constant_term=Decimal('7') / Decimal('9'))
            and r[2] == Plain(normal_vector=Vector(['0', '0', '1']),
                              constant_term=Decimal('2') / Decimal('9'))):
        print('test case 4 failed')
    else:
        print('test case 4 successed')
        LinearSystem_print(s, '原始方程')
        LinearSystem_print(r, '行简化阶梯化后方程')
Example #5
0
def test2():  #线性方程组阶梯化

    p1 = Plain(normal_vector=Vector(['1', '1', '1']), constant_term='1')
    p2 = Plain(normal_vector=Vector(['0', '1', '1']), constant_term='2')
    s = LinearSystem([p1, p2])
    t = s.compute_triangular_form()
    print('*******************************')
    if not (t[0] == p1 and t[1] == p2):
        print('test case 1 failed')
    else:
        print('test case 1 successed')
        LinearSystem_print(s, '原始方程')
        LinearSystem_print(t, '阶梯化后方程')
    print('*******************************')

    p1 = Plain(normal_vector=Vector(['1', '1', '1']), constant_term='1')
    p2 = Plain(normal_vector=Vector(['1', '1', '1']), constant_term='2')
    s = LinearSystem([p1, p2])
    t = s.compute_triangular_form()
    print('*******************************')
    if not (t[0] == p1 and t[1] == Plain(constant_term='1')):
        print('test case 2 failed')
    else:
        print('test case 2 successed')
        LinearSystem_print(s, '原始方程')
        LinearSystem_print(t, '阶梯化后方程')
    print('*******************************')

    p1 = Plain(normal_vector=Vector(['1', '1', '1']), constant_term='1')
    p2 = Plain(normal_vector=Vector(['0', '1', '0']), constant_term='2')
    p3 = Plain(normal_vector=Vector(['1', '1', '-1']), constant_term='3')
    p4 = Plain(normal_vector=Vector(['1', '0', '-2']), constant_term='2')
    s = LinearSystem([p1, p2, p3, p4])
    t = s.compute_triangular_form()
    print('*******************************')
    if not (t[0] == p1 and t[1] == p2
            and t[2] == Plain(normal_vector=Vector(['0', '0', '-2']),
                              constant_term='2') and t[3] == Plain()):
        print('test case 3 failed')
    else:
        print('test case 3 successed')
        LinearSystem_print(s, '原始方程')
        LinearSystem_print(t, '阶梯化后方程')
    print('*******************************')

    p1 = Plain(normal_vector=Vector(['0', '1', '1']), constant_term='1')
    p2 = Plain(normal_vector=Vector(['1', '-1', '1']), constant_term='2')
    p3 = Plain(normal_vector=Vector(['1', '2', '-5']), constant_term='3')
    s = LinearSystem([p1, p2, p3])
    t = s.compute_triangular_form()
    print('*******************************')
    if not (t[0] == Plain(normal_vector=Vector(['1', '-1', '1']),
                          constant_term='2') and t[1]
            == Plain(normal_vector=Vector(['0', '1', '1']), constant_term='1')
            and t[2] == Plain(normal_vector=Vector(['0', '0', '-9']),
                              constant_term='-2')):
        print('test case 4 failed')
    else:
        print('test case 4 successed')
        LinearSystem_print(s, '原始方程')
        LinearSystem_print(t, '阶梯化后方程')
    print('*******************************')
Example #6
0
def test1():  #测试线性方程组的基本操作
    #********************************************
    #判断两直线位置关系,如果相交,输出交点

    p0 = Plain(normal_vector=Vector(['1', '1', '1']), constant_term='1')
    p1 = Plain(normal_vector=Vector(['0', '1', '0']), constant_term='2')
    p2 = Plain(normal_vector=Vector(['1', '1', '-1']), constant_term='3')
    p3 = Plain(normal_vector=Vector(['1', '0', '-2']), constant_term='2')

    s = LinearSystem([p0, p1, p2, p3])

    print(s.indices_of_first_nonzero_terms_in_each_row())
    print('{},{},{},{}'.format(s[0], s[1], s[2], s[3]))
    print(len(s))
    print(s)

    s[0] = p1
    print(s)

    print(MyDecimal('1e-9').is_near_zero())
    print(MyDecimal('1e-11').is_near_zero())

    p0 = Plain(normal_vector=Vector(['1', '1', '1']), constant_term='1')
    p1 = Plain(normal_vector=Vector(['0', '1', '0']), constant_term='2')
    p2 = Plain(normal_vector=Vector(['1', '1', '-1']), constant_term='3')
    p3 = Plain(normal_vector=Vector(['1', '0', '-2']), constant_term='2')

    s = LinearSystem([p0, p1, p2, p3])

    LinearSystem_print(s, '原始方程组')
    #交换等式
    s.swap_rows(0, 1)
    print(s[2].normal_vector.is_parallel_to(p2.normal_vector))
    if not (s[0] == p1 and s[1] == p0 and s[2] == p2 and s[3] == p3):
        print('test case 1 failed')
    else:
        print('test case 1 successed')
    LinearSystem_print(s, '交换1-2行')

    s.swap_rows(1, 3)
    if not (s[0] == p1 and s[1] == p3 and s[2] == p2 and s[3] == p0):
        print('test case 2 failed')
    else:
        print('test case 2 successed')
    LinearSystem_print(s, '交换2-4行')

    s.swap_rows(3, 1)
    if not (s[0] == p1 and s[1] == p0 and s[2] == p2 and s[3] == p3):
        print('test case 3 failed')
    else:
        print('test case 3 successed')
    LinearSystem_print(s, '交换4-2行')

    s.multiply_coefficient_and_row(1, 0)
    if not (s[0] == p1 and s[1] == p0 and s[2] == p2 and s[3] == p3):
        print('test case 4 failed')
    else:
        print('test case 4 successed')
    LinearSystem_print(s, '方程1乘1')

    s.multiply_coefficient_and_row(-1, 2)
    if not (s[0] == p1 and s[1] == p0
            and s[2] == Plain(normal_vector=Vector(['-1', '-1', '1']),
                              constant_term='-3') and s[3] == p3):
        print('test case 5 failed')
    else:
        print('test case 5 successed')
    LinearSystem_print(s, '方程3乘-1')

    s.multiply_coefficient_and_row(10, 1)
    if not (s[0] == p1 and s[1] == Plain(
            normal_vector=Vector(['10', '10', '10']), constant_term='10')
            and s[2] == Plain(normal_vector=Vector(['-1', '-1', '1']),
                              constant_term='-3') and s[3] == p3):
        print('test case 6 failed')
    else:
        print('test case 6 successed')
    LinearSystem_print(s, '方程2乘10')

    s.add_multiple_times_row_to_row(0, 0, 1)
    if not (s[0] == p1 and s[1] == Plain(
            normal_vector=Vector(['10', '10', '10']), constant_term='10')
            and s[2] == Plain(normal_vector=Vector(['-1', '-1', '1']),
                              constant_term='-3') and s[3] == p3):
        print('test case 7 failed')
    else:
        print('test case 7 successed')
    LinearSystem_print(s, '方程1乘0,加到方程2')

    s.add_multiple_times_row_to_row(1, 0, 1)
    if not (s[0] == p1 and s[1] == Plain(
            normal_vector=Vector(['10', '11', '10']), constant_term='12')
            and s[2] == Plain(normal_vector=Vector(['-1', '-1', '1']),
                              constant_term='-3') and s[3] == p3):
        print('test case 8 failed')
    else:
        print('test case 8 successed')
    LinearSystem_print(s, '方程1乘1,加到方程2')

    s.add_multiple_times_row_to_row(-1, 1, 0)
    if not (s[0] == Plain(normal_vector=Vector(['-10', '-10', '-10']),
                          constant_term='-10')
            and s[1] == Plain(normal_vector=Vector(['10', '11', '10']),
                              constant_term='12')
            and s[2] == Plain(normal_vector=Vector(['-1', '-1', '1']),
                              constant_term='-3') and s[3] == p3):
        print('test case 9 failed')
    else:
        print('test case 9 successed')
    LinearSystem_print(s, '方程2乘-1,加到方程1')
Example #7
0
import default
from vehicle import Vehicle
from train import Train
from plain import Plain

default.start(36)

if __name__ == "__main__":
    car = Vehicle('privat', 5, 'free')
    car.print_info()
    print(car.get_vehicle())

    train = Train('public', 340, 'West-North', 'electricity')
    train.print_info()
    print(train.get_train())

    plain = Plain('military', 16, 'FREE', 'react fuel', 130)
    plain.print_info()
    print(plain.get_plain())

default.end()
Example #8
0
from plain import Plain

if __name__ == "__main__":
	app         = Plain()	
	app.update()
Example #9
0
    for t2 in tiles:
        t1.delete_common(t2)

for t1 in tiles:
    t1.update()

mult = 1
for t in tiles:
    print(t.nr, t.border)
    if len(t.border) == 2:
        mult *= t.nr

print(mult)

print('part two')
plain = Plain(no_elements, tiles)
# test20.txt
plain.tiles[0][0].rotate_counter_clockwise()
print(plain)

# input.txt
# plain.tiles[0][0].rotate_clockwise()
# plain.tiles[0][0].flip_upside_down()
for y in range(no_elements):
    for x in range(no_elements):
        i = 1
        while not plain.check_wisely((x, y)):
            plain.change_wisely((x, y))
            i += 1
print('got it')
print(plain.get_centers_string())
Example #10
0
from plain import Plain
import db

if __name__ == "__main__":
	app = Plain()
	app.static = 'D:\\develop\\kxh.github.io'
	app.generate_static()