Example #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-m',
                        '--model_dir',
                        type=str,
                        help='Path to the trained RUN-CSP instance')
    parser.add_argument('-v',
                        '--n_variables',
                        type=int,
                        default=100,
                        help='Number of variables in each training instance.')
    parser.add_argument(
        '--c_min',
        type=int,
        default=100,
        help='Minimum number of clauses in each training instance.')
    parser.add_argument(
        '--c_max',
        type=int,
        default=600,
        help='Maximum number of clauses in each training instance.')
    parser.add_argument('-i',
                        '--n_instances',
                        type=int,
                        default=100,
                        help='Number of instances for training.')
    parser.add_argument('-t',
                        '--t_max',
                        type=int,
                        default=40,
                        help='Number of network iterations t_max')
    parser.add_argument('-a',
                        '--attempts',
                        type=int,
                        default=64,
                        help='Number of attempts to boost results')
    args = parser.parse_args()

    # create RUN_CSP instance for given constraint language
    network = RUN_CSP.load(args.model_dir)
    language = network.language

    print(f'Generating {args.n_instances} evaluation instances')
    eval_instances = [
        CSP_Instance.generate_random(args.n_variables,
                                     np.random.randint(args.c_min, args.c_max),
                                     language)
        for _ in tqdm(range(args.n_instances))
    ]

    # train and store the network
    evaluate_boosted(network, eval_instances, args.t_max, args.attempts)
Example #2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-m',
                        '--model_dir',
                        type=str,
                        help='Path to the trained RUN-CSP instance')
    parser.add_argument(
        '-t',
        '--t_max',
        type=int,
        default=100,
        help=
        'Number of iterations t_max for which RUN-CSP runs on each instance')
    parser.add_argument('-a',
                        '--attempts',
                        type=int,
                        default=64,
                        help='Attempts for each graph')
    parser.add_argument(
        '-d',
        '--data_path',
        default=None,
        help=
        'Path to the evaluation data. Expects a directory with graphs in dimacs format.'
    )
    parser.add_argument(
        '-v',
        '--n_variables',
        type=int,
        default=400,
        help=
        'Number of variables in each training instance. Only used when --data_path is not specified.'
    )
    parser.add_argument(
        '-c',
        '--n_clauses',
        type=int,
        default=1000,
        help=
        'Number of clauses in each training instance. Only used when --data_path is not specified.'
    )
    parser.add_argument(
        '-i',
        '--n_instances',
        type=int,
        default=100,
        help=
        'Number of instances for training. Only used when --data_path is not specified.'
    )
    args = parser.parse_args()

    network = RUN_CSP.load(args.model_dir)
    language = network.language

    if args.data_path is not None:
        print('loading graphs...')
        names, graphs = data_utils.load_graphs(args.data_path)
        instances = [
            CSP_Instance.graph_to_csp_instance(g, language, 'NEQ', name=n)
            for n, g in zip(names, graphs)
        ]
    else:
        print(f'Generating {args.n_instances} training instances')
        instances = [
            CSP_Instance.generate_random(args.n_variables, args.n_clauses,
                                         language)
            for _ in tqdm(range(args.n_instances))
        ]

    conflicting_edges = evaluate_boosted(network,
                                         instances,
                                         args.t_max,
                                         attempts=args.attempts)
Example #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '-l',
        '--language_config_path',
        type=str,
        help='The path to a json file that specifies the constraint language')
    parser.add_argument(
        '-m',
        '--model_dir',
        type=str,
        help=
        'Path to the model directory where the trained RUN-CSP instance will be stored'
    )
    parser.add_argument('-v',
                        '--n_variables',
                        type=int,
                        default=100,
                        help='Number of variables in each training instance.')
    parser.add_argument(
        '--c_min',
        type=int,
        default=100,
        help='Minimum number of clauses in each training instance.')
    parser.add_argument(
        '--c_max',
        type=int,
        default=600,
        help='Maximum number of clauses in each training instance.')
    parser.add_argument('-i',
                        '--n_instances',
                        type=int,
                        default=4000,
                        help='Number of instances for training.')
    parser.add_argument(
        '-t',
        '--t_max',
        type=int,
        default=30,
        help=
        'Number of iterations t_max for which RUN-CSP runs on each instance')
    parser.add_argument('-s',
                        '--state_size',
                        type=int,
                        default=128,
                        help='Size of the variable states in RUN-CSP')
    parser.add_argument('-b',
                        '--batch_size',
                        type=int,
                        default=10,
                        help='Batch size used during training')
    parser.add_argument('-e',
                        '--epochs',
                        type=int,
                        default=25,
                        help='Number of training epochs')
    args = parser.parse_args()

    print(f'Loading constraint language from {args.language_config_path}')
    language = Constraint_Language.load(args.language_config_path)
    # create RUN_CSP instance for given constraint language
    network = RUN_CSP(args.model_dir, language, args.state_size)

    print(f'Generating {args.n_instances} training instances')
    train_instances = [
        CSP_Instance.generate_random(args.n_variables,
                                     np.random.randint(args.c_min, args.c_max),
                                     language)
        for _ in tqdm(range(args.n_instances))
    ]
    # combine instances into batches
    train_batches = CSP_Instance.batch_instances(train_instances,
                                                 args.batch_size)

    # train and store the network
    train(network, train_batches, args.t_max, args.epochs)