Beispiel #1
0
    def __init__(self, graph):
        self.threshold = 10000000
        self.name = graph.split(".")[0]
        self.G = tools.Graph(inputfile=graph)

        self.G.degOrdering()

        self.model = grb.Model()
        self.model.setAttr("ModelSense", -1)
Beispiel #2
0
def Main():

    parser = argparse.ArgumentParser()
    parser.add_argument("instance_name", help="determine instance name" +\
                 ", make sure the instance already exist in the directory")

    group = parser.add_argument_group("Formulation Type")
    FormulationType = group.add_mutually_exclusive_group(required=True)
    FormulationType.add_argument("-c",
                                 "--conflict",
                                 help="conflict model",
                                 action="store_true")
    FormulationType.add_argument("-s",
                                 "--sparse",
                                 help="sparse model",
                                 action="store_true")
    FormulationType.add_argument("-sJ", "--sparseJeroslow", help="Jeroslow Extended" +\
                          "+sparse formulation",action="store_true")
    FormulationType.add_argument("-cB", "--conflictBalas", help="Balas Extended" +\
                          "+conflict",action="store_true")


    parser.add_argument("-NonDef","--Nondefault_model_setting", help="turn off" +\
                        "the gurobi default setting:cut/presolve/heuristic on"
                        , action="store_true")
    parser.add_argument("-cBPerfect","--isPerfect_cB", help="check if" +\
                        " the instance satisfies the sufficient condition for BEF formulation to be perfect"
                        , action="store_true")

    args = parser.parse_args()

    if args.conflict:
        C = formulations.conflict(args.instance_name)
    if args.sparse:
        C = formulations.sparse(args.instance_name)
    if args.sparseJeroslow:
        C = formulations.sparseJeroslow(args.instance_name)
    if args.conflictBalas:
        C = formulations.conflictBalas(args.instance_name)

    if args.Nondefault_model_setting:
        C.setModelAttr()

    if args.isPerfect_cB:
        graphTest = tools.Graph(inputfile=args.instance_name)
        sys.stderr.write("%s is conflictBalas Perfect: " %
                         args.instance_name.split(".")[0])
        sys.stderr.write("%r \t" % graphTest.isconflictBalasPerfect())

    #solve the model with Gurobi solver
    C.solveGurobi()
Beispiel #3
0
import tools

# Collect data
n = 15 # n = 300 works fine
p = 0.4 # prob of (i,j) \in E
k = 2 # number of pairs
graph = tools.Graph(n = n,p = p)
edges_weights = tools.get_weights(graph)
vertices = graph.vertices()

from gurobipy import *

edges, weights = multidict(edges_weights)

# Create a new model
m = Model("muticut")

# Create variables
cuts = {} 
for e in edges:
    cuts[e] = m.addVar(vtype = GRB.BINARY) # if we cut edge e
    
# Integrate new variables
m.update()

# Set objective
m.setObjective(sum(cuts[e]*weights[e] for e in edges), GRB.MINIMIZE) # minimize cut-cost

# Add constraints:
# WLOG source-sink pairs are (0,1),(2,3) ....
for i in range(k):
    return teach_file, repeat_files, gps_files


if __name__ == "__main__":

    results_folder = "/path/to/results"
    if not os.path.exists(results_folder):
        os.makedirs(results_folder)

    # Read in data from text files
    data_folder = "/path/to/data"
    teach_files, repeat_files, gps_files = get_run_files(data_folder)

    # Create graph
    g = tools.Graph(teach_files, repeat_files, gps_files=gps_files)

    # Iterate over all runs
    for run_id in range(len(repeat_files) + 1):
        if run_id in gps_files.keys():
            lat, lon = [], []

            pose_id = 0
            vertex_id = (run_id, pose_id)

            # Iterate sequentially over all vertices in a run
            while g.is_vertex(vertex_id):
                vertex = g.get_vertex(vertex_id)

                # Get transform between adjacent vertices and integrate pose
                if (vertex.latitude is not None) and (vertex.longitude
Beispiel #5
0
                    data_dir,
                    str(i).zfill(6))
                if os.path.isfile(gps_time):
                    gps_timestamps[i] = gps_time

    return teach, repeats, image_timestamps, gps_filenames, gps_timestamps


if __name__ == "__main__":
    # Read in data from text files
    data_folder = "/home/path/to/data"
    teach_run, repeat_runs, image_times, gps_files, gps_times = get_run_files(
        data_folder)

    # Create graph
    g = tools.Graph(teach_run, repeat_runs, image_times, gps_files, gps_times)

    # Extract sub-graph to work with (optional)
    g = g.get_subgraph(0, 500)

    # Example vertices
    v1 = (0, 67)
    v2 = (1, 62)

    # Check that the vertices are in our graph
    if g.is_vertex(v1) and g.is_vertex(v2):

        # Get path between vertices
        path, _ = g.get_path(v1, v2)

        # Get the topological distance between the vertices
Beispiel #6
0
    return teach_file, repeat_files


if __name__ == "__main__":

    results_folder = "/path/to/results"
    if not os.path.exists(results_folder):
        os.makedirs(results_folder)

    # Read in data from text files
    data_folder = "/path/to/data"
    teach_file, repeat_files = get_run_files(data_folder)

    # Create graph
    g = tools.Graph(teach_file, repeat_files)

    # Iterate over all runs
    for run_id in range(len(repeat_files) + 1):

        x, y = [], []
        T_curr_start = Transform(np.eye(3), np.zeros((3, )))

        pose_id = 0
        vertex_id_curr = (run_id, pose_id)
        vertex_id_next = (run_id, pose_id + 1)

        # Iterate sequentially over all vertices in a run
        while g.is_vertex(vertex_id_curr) and g.is_vertex(vertex_id_next):

            # Get transform between adjacent vertices and integrate pose