Пример #1
0
def _run_ilp(dataset: str, name: str) -> Tuple[int, float, str]:
    """Run ILP on all datasets.

    Parameters
    ----------
    dataset : str
        Dataset name.
    name : str
        FCL name.

    Returns
    -------
    Tuple[int, float, str]
        Solution size, time, and certificate.
    """
    # Execute
    solution = solve_ilp(read_edgelist(
        str(FCL_DATA_DIR / dataset / 'snap' / (name + SNAP_DATA_EXT))),
                         formulation='VC',
                         solver='CPLEX',
                         threads=4,
                         timelimit=EXACT_TIMEOUT,
                         convert_to_oct=True)

    # Return
    return solution.opt, solution.time, solution.certificate
Пример #2
0
def _run_ilp(dataset: str, name: str, timeout: int) -> Tuple[int, float, str]:
    """Run ILP on all datasets.

    Parameters
    ----------
    dataset : str
        Dataset name.
    name : str
        FCL name.
    timeout : int
        Timeout in seconds.

    Returns
    -------
    Tuple[int, float, str]
        Solution size, time, and certificate.
    """
    # Execute
    # Solved using CPLEX with timeout for a partial solution
    solution = solve_ilp(read_edgelist(
        str(FCL_DATA_DIR / dataset / 'snap/{}.snap'.format(name))),
                         formulation='VC',
                         solver='CPLEX',
                         threads=1,
                         timelimit=timeout,
                         convert_to_oct=True)

    # Return
    return solution.opt, solution.time, solution.certificate
Пример #3
0
def _run_ilp(dataset, threads=4):
    """Run the designmated ILP solver on a dataset."""

    # Compute solution
    solution = solve_ilp(read_edgelist(
        str(SNAP_DATA_DIR / (dataset + SNAP_DATA_EXT))),
                         formulation='VC',
                         solver='CPLEX',
                         threads=threads,
                         timelimit=EXACT_TIMEOUT,
                         convert_to_oct=True)

    # Return solution
    return solution.time, solution.opt, solution.certificate
Пример #4
0
def main():
    """Run experiments"""

    # Compute datasets
    datasets = list(
        map(lambda d: str(SNAP_DATA_DIR / (d + SNAP_DATA_EXT)), preprocessed))

    # Log
    logger.info('Starting CPLEX Experiment')

    # Generate experiments
    experiments = product(PREPROCESSING_TIMEOUTS, datasets)

    # Open output file
    with open(str(CPLEX_RESULTS_DATA_FILE), 'w') as output:

        # Get writer
        writer = csv.writer(output)

        # Write header
        writer.writerow(HEURISTICS_CSV_HEADERS)

        # Run experiments
        for experiment in experiments:

            try:

                # Log
                logger.info('Starting experiment timeout={} dataset={}'.format(
                    *experiment))

                # Run cplex
                solution = solve(read_edgelist(experiment[1]),
                                 formulation='VC',
                                 solver='CPLEX',
                                 threads=4,
                                 timelimit=experiment[0],
                                 convert_to_oct=True)

                # Write
                writer.writerow([
                    os.path.basename(experiment[1]), experiment[0],
                    solution.opt, solution.time, solution.certificate
                ])
                output.flush()

            except Exception as e:

                logger.error(e)
Пример #5
0
def _execute_cplex(configurations, outfile, csv_writer):
    """
    Execute CPLEX on a list of (data, timeout) configurations, writing output
    to csv_writer.
    """
    logger.info('Starting CPLEX Heurisitc Experiment')

    # Execute all configurations
    for (dataset, timeout) in configurations:
        try:
            logger.info(
                'Executing CPLEX on {} with timeout {}s'
                .format(dataset, timeout)
            )

            # Execute CPLEX on one configuration
            solution = solve_ilp(
                read_edgelist(dataset),
                formulation='VC',
                solver='CPLEX',
                threads=1,
                timelimit=timeout,
                convert_to_oct=True
            )

            # Write
            csv_writer.writerow([
                dataset.split('/')[-1].replace('.snap', ''),
                'ilp_1',
                timeout,
                solution.time,
                solution.opt,
                solution.certificate
            ])
            outfile.flush()

        except Exception as e:
            csv_writer.writerow([
                dataset.split('/')[-1].replace('.snap', ''),
                'ilp_1',
                timeout,
                float('nan'),
                float('nan'),
                float('nan')
            ])
            outfile.flush()
            logger.error(e)
Пример #6
0
def _run_experiments():
    """Run experiments."""

    # Generate full (formulation, file) data list
    DATA = list(
        chain.from_iterable(
            map(lambda f: _dataset_to_formulations(f),
                ilp_experiment_datasets)))

    # Generate iterator for experiments
    experiments = product(SOLVERS, EXPERIMENT_MEMORY_LIMITS, DATA)

    # Log
    logger.info('Starting ILP Experiments')
    logger.info('- {} solvers'.format(len(SOLVERS)))
    logger.info('- {} memory limits'.format(len(EXPERIMENT_MEMORY_LIMITS)))
    logger.info('- {} data sets'.format(len(DATA) / 2))

    # Open output file
    with open(str(ILP_RESULTS_FILE_PATH), 'w') as output:

        # Get writer
        writer = csv.writer(output)

        # Write header
        writer.writerow([
            headers.SOLVER, headers.THREADS, headers.MEMORY,
            headers.FORMULATION, headers.DATASET, headers.VERTICES,
            headers.EDGES, headers.TIME, headers.OPT, headers.CERTIFICATE
        ])

        # Iterate over experiments
        for experiment in experiments:

            # Run Experiments
            try:

                # Log
                logger.info(
                    ('Running experiment solver={}, threads={}, '
                     'memlimit={}, dataset={}').format(experiment[0][0],
                                                       experiment[0][1],
                                                       experiment[1],
                                                       experiment[2][1]))

                # Compute solution
                solution = solve(read_edgelist(experiment[2][1]),
                                 solver=experiment[0][0],
                                 threads=experiment[0][1],
                                 formulation=experiment[2][0],
                                 timelimit=EXACT_TIMEOUT,
                                 memlimit=experiment[1],
                                 convert_to_oct=True)

                # Write
                writer.writerow([
                    experiment[0][0], experiment[0][1], experiment[1],
                    experiment[2][0],
                    os.path.splitext(os.path.basename(experiment[2][1]))[0],
                    solution.n, solution.m, solution.time, solution.opt,
                    solution.certificate
                ])
                output.flush()

            # Handle failure
            except Exception as e:
                logger.error(e)