Ejemplo n.º 1
0
import sys
sys.path.append('.')

from wusn.exact import solve
from wusn.commons import WusnInput

if __name__ == '__main__':
    inp = WusnInput.from_file('small_data/test/001.test')
    prob = solve.model_lp(inp)
    out = solve.solve_lp(prob, inp)
    print(out.valid)
    out.plot_to_file('tests/test.png')
Ejemplo n.º 2
0
    'rmc': (uniform_sensors, many_clustered_relays),
    'rfc': (uniform_sensors, few_clustered_relays),
    'br': (bordered_sensors, uniform_relays),
    'cer': (centered_sensors, uniform_relays)
    # 'rb': (uniform_sensors, bordered_relays),
    # 'rce': (uniform_sensors, centered_relays)
}

if __name__ == '__main__':
    args = parse_arguments()

    count = 1
    for name, (fn_s, fn_r) in GENS.items():
        for i in range(args.count):
            sensors_ = fn_s(args.width, args.height, args.depth, args.sensors,
                            args.relays, args.Y)
            relays_ = fn_r(args.width, args.height, args.rheight, args.sensors,
                           args.relays, args.Y)
            inp = WusnInput(sensors=sensors_,
                            relays=relays_,
                            relay_num=args.Y,
                            width=args.width,
                            height=args.height,
                            ignore_cache=True)

            fname = '%s-%03d.test' % (name, i + 1)
            path = os.path.join(args.output_dir, fname)
            print('Saving test case %d to %s' % (count, path))
            count += 1
            inp.to_file(path)
Ejemplo n.º 3
0
def parse_arguments():
    parser = ArgumentParser()

    parser.add_argument('-i', '--input', required=True)
    parser.add_argument('-o', '--output', default='out/exact')
    parser.add_argument('--lax', action='store_true')

    return parser.parse_args()


if __name__ == '__main__':
    args = parse_arguments()
    print('File: %s' % args.input)

    inp = WusnInput.from_file(args.input)
    print('Modeling...')
    prob = solve.model_lp(inp, lax=args.lax)

    print('Solving LP...')
    out = solve.solve_lp(prob, inp)

    test_name = os.path.split(args.input)[-1].split('.')[0]
    if not args.lax:
        save_dir = os.path.join(args.output, test_name)
        print('Saving results to %s ...' % save_dir)
        os.makedirs(save_dir, exist_ok=True)

        out.to_text_file(args.input, os.path.join(save_dir, 'opt.out'))
        out.plot_to_file(os.path.join(save_dir, 'opt.png'))
Ejemplo n.º 4
0
    history = InMemoryHistory()
    plt.ioff()

    print('Enter a path to an input/output file to view its plot.')
    print('Ctrl+C or Ctrl+D to exit.')

    try:
        while True:
            path = prompt('> ', history=history)
            if not os.path.exists(path):
                print('No such path exists.')
                continue

            try:
                if path.endswith('.test'):
                    obj = WusnInput.from_file(path)
                else:
                    obj = WusnOutput.from_text_file(path)
            except Exception:
                print('Failed to open file.')
                continue

            fig = plt.figure()
            ax = Axes3D(fig)
            obj.plot(ax, highlight_max=False)
            ax.legend()
            plt.show()
            fig.clf()

    except (KeyboardInterrupt, EOFError):
        print()
Ejemplo n.º 5
0
    # print('Enter a path to an input/output file to gens.')
    # path_1 = input()
    # print('Enter a path to an input/output file to matrix.')
    # path_2 = input()
    print('Enter a path to an input/output file to data.')
    path_3 = input()

    try:

        if not os.path.exists(path_1) or not os.path.exists(
                path_2) or not os.path.exists(path_3):
            print('No such path exists.')
        try:
            gens = ToA.from_file_gens(path=path_1)
            matrix = ToA.from_file_matrix(path=path_2)
            obj = WusnInput.from_file(path_3, True)
        except Exception:
            print('Failed')

        anchors = obj.anchors
        exact_non_anchors = obj.non_anchors
        init_population(80)
        individual_number = len(population)
        population.sort(key=fitness)
        crossover_selection_size = int(len(population) * 4 / 5)
        mutation_selection_size = int(len(population) / 2)
        for t in range(generation):
            print(t)
            candi_pop = population.copy()
            crossover_candidates = []
            mutation_candidates = []
Ejemplo n.º 6
0
import sys
sys.path.append('.')

from wusn.commons import WusnInput


if __name__ == '__main__':
    inp1 = WusnInput.from_file('small_data/001.test', ignore_cache=True)
    inp1.cache_losses()
    inp2 = WusnInput.from_file('small_data/001.test', ignore_cache=False)
Ejemplo n.º 7
0
import sys
sys.path.append('.')

from wusn.commons import WusnInput
from wusn.yuan.lurns import lurns1, lurns2

if __name__ == '__main__':
    inp = WusnInput.from_file('data/001.test')

    out1 = lurns1.lurns1(inp)
    out1.to_text_file('data/001.test', 'tests/001_lu.out')
    # out2 = lurns2.lurns2(inp)
Ejemplo n.º 8
0
            x, y = uniform_point(width, height)
            rn = Point(x=x, y=y, r=radius, order=i + M)
        non_anchors.append(rn)
    return non_anchors


GENS = {
    'rr': (uniform_anchors, uniform_non_anchors),
    # 'rhr': (uniform_sensors, uniform_half_relays),
}

if __name__ == '__main__':
    args = parse_arguments()
    count = 1
    for name, (fn_s, fn_r) in GENS.items():
        for i in range(args.count):
            anchors_ = fn_s(args.width, args.height, args.anchors, args.radius)
            non_anchors_ = fn_r(args.width, args.height, args.non_anchors,
                                args.anchors, args.radius)
            inp = WusnInput(anchors=anchors_,
                            non_anchors=non_anchors_,
                            width=args.width,
                            height=args.height,
                            ignore_cache=True)

            fname = '%s-%03d.test' % (name, i + 1)
            path = os.path.join(args.output_dir, fname)
            print('Saving test case %d to %s' % (count, path))
            count += 1
            inp.to_file(path)