Skip to content

Instantly share code, notes, and snippets.

@ozansener
Last active May 3, 2017 02:25
Show Gist options
  • Save ozansener/ef740e57654d52679e43cdcd2f40dabf to your computer and use it in GitHub Desktop.
Save ozansener/ef740e57654d52679e43cdcd2f40dabf to your computer and use it in GitHub Desktop.
from pulp import *
l = open('abc').read().split('\n')
title = l[0]
ent = title.split(',')
paper_ids = ent[2:]
num_papers = len(paper_ids)
print num_papers
print paper_ids
num_reviewers = len(l)-1
print num_reviewers
sen_sum = 0
pref = []
for pa in range(num_papers):
pref.append([])
rev_quality = []
reviewer_names = []
for rev_id in range(1,len(l)):
entries = l[rev_id].split(',')
name = entries[0]
reviewer_names.append(name)
senior = int(entries[1])
sen_sum += senior
if senior>0:
rev_quality.append(1)
else:
rev_quality.append(0)
scores = map(lambda x:int(x) if x else 0,entries[2:])
for i,sc in enumerate(scores):
pref[i].append(sc)
print name,senior,scores
print sen_sum
print reviewer_names
print rev_quality
papers = range(num_papers)
reviewers = range(num_reviewers)
review_types = range(2)
assignments = LpVariable.dicts("Assign",(papers, reviewers, review_types),0,1,LpInteger)
prob = LpProblem('ICCV17', LpMaximize)
# Objective
prob += lpSum([assignments[pa][re][k]*pref[pa][re] if k<1 else 0.5*assignments[pa][re][k]*pref[pa][re] for pa in papers for re in reviewers for k in range(2)])
#prob += lpSum([0.5*assignments[pa][re][1]*pref[pa][re] for pa in papers for re in reviewers])
# Each paper has two reviewers
for pa in papers:
prob += lpSum([assignments[pa][re][k] for re in reviewers for k in range(2)]) == 2, ""
# Each paper has one full review
for pa in papers:
prob += lpSum([assignments[pa][re][0] for re in reviewers]) >= 1, ""
# Each paper has one senior reviewers
for pa in papers:
prob += lpSum([assignments[pa][re][k]*rev_quality[re] for re in reviewers for k in range(2)]) >= 1, ""
# Each reviewer has 3 full papers
for re in reviewers:
prob += lpSum([assignments[pa][re][0] for pa in papers]) == 2, ""
# Each reviewer has at most 1 short papers
for re in reviewers:
prob += lpSum([assignments[pa][re][1] for pa in papers]) <= 2, ""
# The problem data is written to an .lp file
prob.writeLP("iccv.lp")
# The problem is solved using PuLP's choice of Solver
prob.solve()
# The status of the solution is printed to the screen
print("Status:", LpStatus[prob.status])
ts=0
tn=0
for pa in papers:
full_r = []
short_r = []
fr = 0
sr = 0
cf = 0
cs = 0
for re in reviewers:
if value(assignments[pa][re][0]) > 0:
fr+=1
full_r.append(reviewer_names[re])
ts+=pref[pa][re]
tn+=1
cf+=pref[pa][re]
if value(assignments[pa][re][1]) > 0:
sr +=1
ts += pref[pa][re]
tn+=1
short_r.append(reviewer_names[re])
cs +=pref[pa][re]
print paper_ids[pa],"F:",full_r,"S:",short_r#,cf,cs
print "full_",ts,tn
for re in reviewers:
full_p = []
short_p = []
cf=0
cs=0
for pa in papers:
if value(assignments[pa][re][0]) > 0:
full_p.append(paper_ids[pa])
cf+=pref[pa][re]
if value(assignments[pa][re][1]) > 0:
short_p.append(paper_ids[pa])
cs+=pref[pa][re]
print reviewer_names[re]+"\t"+'\t'.join(full_p)+"\t"+"\t".join(short_p)#,cf,cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment