Changeset 2107
 Timestamp:
 Jan 2, 2010 2:03:02 AM (10 years ago)
 Location:
 coopr.pyomo/trunk/examples/pyomo/pmedian
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

coopr.pyomo/trunk/examples/pyomo/pmedian/solver1.py
r2044 r2107 26 26 soln.value = val 27 27 soln.status = SolutionStatus.feasible 28 for j in range(1,n+1):28 for j in xsequence(n): 29 29 if instance.y[j].value is 1: 30 30 soln.variable[instance.y[j].name] = 1 … … 38 38 fixed=set() 39 39 # Initialize 40 for j in range(1,n+1):40 for j in xsequence(n): 41 41 instance.y[j].value=0 42 42 # Greedily fix the next best facility 43 for i in range(1,p+1):43 for i in xsequence(p): 44 44 best = None 45 45 ndx=j 46 for j in range(1,n+1):46 for j in xsequence(n): 47 47 if j in fixed: 48 48 continue … … 50 50 # Compute value 51 51 val = 0.0 52 for kk in range(1,m+1):52 for kk in xsequence(m): 53 53 tmp=copy.copy(fixed) 54 54 tmp.add(j) 
coopr.pyomo/trunk/examples/pyomo/pmedian/solver2.py
r2063 r2107 28 28 soln.value = val 29 29 soln.status = SolutionStatus.feasible 30 for j in range(1,n+1):30 for j in xsequence(n): 31 31 soln.variable[instance.y[j].name] = sol[j1] 32 32 # Return results … … 36 36 def _random(self, instance): 37 37 sol = [0]*instance.N.value 38 for j in range(0,instance.P.value):38 for j in xrange(instance.P.value): 39 39 sol[j] = 1 40 40 # Generate 100 random solutions, and keep the best 41 41 best = None 42 42 best_sol = [] 43 for kk in range(100):43 for kk in xrange(100): 44 44 random.shuffle(sol) 45 45 # Compute value 46 46 val=0.0 47 for j in range(1,instance.M.value+1):47 for j in xsequence(instance.M.value): 48 48 val += min([instance.d[i,j].value 49 for i in range(1,instance.N.value+1)49 for i in xsequence(instance.N.value) 50 50 if sol[i1] == 1]) 51 51 if best is None or val < best:
Note: See TracChangeset
for help on using the changeset viewer.