#!/usr/bin/python # import the Gurobi tools from gurobipy import * ###################### # my presentation scheduling program, 18 groups, 3 presentations per day n = 18 # the number of groups d = 9 # the number of presentation days # temporarily, for easier debugging and viewing # n = 5 d = 4 input_data = "data5x4.txt" # set up the model # jf_model = Model('scheduler') # set up an n by d array of variables # vars = jf_model.addVars(n,d, vtype=GRB.BINARY, name='sched') # Each group must take one day # jf_model.addConstrs( (vars.sum(i,'*') == 1 for i in range(n) ), name='Group') # Each day has at most three presentations # jf_model.addConstrs( (vars.sum('*',j) <= 3 for j in range(d) ), name='Days') # Build the objective function from the file named input_data my_obj = LinExpr() # set up the objective i = 0.0 for v in jf_model.getVars(): i = i + 0.1 my_obj.addTerms( i , v ) inp = open(input_data,"r") # Initialize for the "while" loop: i = 0 not_done = True # while ( not_done ): inp_line = inp.readline() parts_of_line = inp_line.split(",") if ( len(parts_of_line) < 2 ): not_done = False # end of input file else: print("Name of project: " + parts_of_line[0]) prefs = parts_of_line[1] for j in range( len(prefs) - 1 ): day = int(prefs[j]) print("Choice " +str(j+1)+ ": " + str(day) ) print("Weight: " + str(d-j) + " in entry: " + str(i)+ "," +str(day-1)) my_obj.addTerms( d - j , vars[i,day-1] ) i = i + 1 # check by typing "my_obj" into Python/Gurobi # jf_model.setObjective( my_obj, GRB.MAXIMIZE) jf_model.optimize() jf_model.printAttr("X") # for v in jf_model.getVars(): # print('%s %g' % (v.varName, v.x))