В настоящее время я реализую сложную микробную пищевую сеть в Python, используя SciPy.integrate.ode . Мне нужна способность легко добавлять виды и реакции в систему, поэтому я должен написать нечто общее. Моя схема выглядит примерно так:
class Reaction(object):
def __init__(self):
#stuff common to all reactions
def __getReactionRate(self, **kwargs):
raise NotImplementedError
... Reaction subclasses that
... implement specific types of reactions
class Species(object):
def __init__(self, reactionsDict):
self.reactionsDict = reactionsDict
#reactionsDict looks like {'ReactionName':reactionObject, ...}
#stuff common to all species
def sumOverAllReactionsForThisSpecies(self, **kwargs):
#loop over all the reactions and return the
#cumulative change in the concentrations of all solutes
...Species subclasses where for each species
... are defined and passed to the superclass constructor
class FermentationChamber(object):
def __init__(self, speciesList, timeToSolve, *args):
#do initialization
def step(self):
#loop over each species, which in turn loops
#over each reaction inside it and return a
#cumulative dictionary of total change for each
#solute in the whole system
if __name__==__main__:
f = FermentationChamber(...)
o = ode(...) #initialize ode solver
while o.successful() and o.t<timeToSolve:
o.integrate()
#process o.t and o.y (o.t contains the time points
#and o.y contains the solution matrix)
Итак, вопрос в том, когда я перебираю словари в Species.sumOverAllReactionsForThisSpecies()
и FermentationChamber.step()
, является ли порядок итераций словарей гарантированно одинаковым, если между словарями между первым и первым не будет добавлено или удалено ни одного элемента последняя итерация? То есть можно ли предположить, что порядок массива numpy, создаваемого на каждой итерации из словаря, не будет меняться? Например, если словарь имеет формат {'Glucose': 10, 'Fructose': 12}, если массив, созданный из этого словаря, будет всегда иметь тот же порядок (не имеет значения, что это порядок, пока он детерминирован).
Извините за мегапост, я просто хотел сообщить вам, откуда я.