Changeset 2107


Ignore:
Timestamp:
Jan 2, 2010 2:03:02 AM (10 years ago)
Author:
wehart
Message:

Updating solver heuristics to use xrange() and xsequence()

Location:
coopr.pyomo/trunk/examples/pyomo/p-median
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • coopr.pyomo/trunk/examples/pyomo/p-median/solver1.py

    r2044 r2107  
    2626        soln.value = val
    2727        soln.status = SolutionStatus.feasible
    28         for j in range(1,n+1):
     28        for j in xsequence(n):
    2929            if instance.y[j].value is 1:
    3030                soln.variable[instance.y[j].name] = 1
     
    3838        fixed=set()
    3939        # Initialize
    40         for j in range(1,n+1):
     40        for j in xsequence(n):
    4141            instance.y[j].value=0
    4242        # Greedily fix the next best facility
    43         for i in range(1,p+1):
     43        for i in xsequence(p):
    4444            best = None
    4545            ndx=j
    46             for j in range(1,n+1):
     46            for j in xsequence(n):
    4747                if j in fixed:
    4848                    continue
     
    5050                # Compute value
    5151                val = 0.0
    52                 for kk in range(1,m+1):
     52                for kk in xsequence(m):
    5353                    tmp=copy.copy(fixed)
    5454                    tmp.add(j)
  • coopr.pyomo/trunk/examples/pyomo/p-median/solver2.py

    r2063 r2107  
    2828        soln.value = val
    2929        soln.status = SolutionStatus.feasible
    30         for j in range(1,n+1):
     30        for j in xsequence(n):
    3131            soln.variable[instance.y[j].name] = sol[j-1]
    3232        # Return results
     
    3636    def _random(self, instance):
    3737        sol = [0]*instance.N.value
    38         for j in range(0,instance.P.value):
     38        for j in xrange(instance.P.value):
    3939            sol[j] = 1
    4040        # Generate 100 random solutions, and keep the best
    4141        best = None
    4242        best_sol = []
    43         for kk in range(100):
     43        for kk in xrange(100):
    4444            random.shuffle(sol)
    4545            # Compute value
    4646            val=0.0
    47             for j in range(1,instance.M.value+1):
     47            for j in xsequence(instance.M.value):
    4848                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)
    5050                            if sol[i-1] == 1])
    5151            if best is None or val < best:
Note: See TracChangeset for help on using the changeset viewer.