python - Why is the value not changing in the objects in the Lists? -


in code i'm trying implement constraint such total equal demand using sum , respective division of can see in code in

self.max[o].x=self.max[o].x*demand/tot 

this implementing constraint.

however when using direct variables without using lists code working fine, after introduced list have started having problem value not changing expected be, or way should logically change.

you can see tot value after implementation of code should equal demand, not happening.

class chromosome:     def __init__(self,identifier):         self.x=d.pdf[identifier].rvs()         self.identifier=identifier  class individual:     def __init__(self):         self.max=[]         o in range(3):             self.max.append(chromosome(o))          tot=sum(chromosome.x chromosome in self.max)         print("before changing total {}".format(tot))          in range(d.coef.shape[1]):             print("individual values before {}".format(self.max[o].x))             self.max[o].x=self.max[o].x*demand/tot             print("individual values after {}".format(self.max[o].x))           tot=sum(chromosome.x chromosome in self.max)         print("after changing total {}".format(tot)) 

here d.pdf list of custom probability distribution created in following manner.

from scipy import stats import scipy.ndimage j in range(3):         d.space[j]=np.ones(demand, dtype=np.float32)         d.space[j]=scipy.ndimage.filters.gaussian_filter1d(d.space[j],10)         d.space[j]=d.space[j]/d.space[j].sum()         d.pdf[j] = stats.rv_discrete(name='pdfx'.format(j), values=(np.arange(demand), d.space[j])) 

please going wrong. don't see logical mistakes, there issue using lists such work please let me know.

in second loop, variable i, yet you're referencing o (from previous loop), you're overwriting last item in self.max several times.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -