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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.