Tôi hiện đang triển khai một trang web thực phẩm vi sinh phức tạp bằng Python sử dụng SciPy.integrate.ode. Tôi cần khả năng dễ dàng thêm loài và phản ứng vào hệ thống, vì vậy tôi phải viết mã một cái gì đó khá chung chung. chương trình của tôi trông giống như sau:Thứ tự của một từ điển Python có được đảm bảo lặp lại không?
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)
Vì vậy, câu hỏi là, khi tôi lặp qua các từ điển trong Species.sumOverAllReactionsForThisSpecies()
và FermentationChamber.step()
, là thứ tự lần lặp của từ điển đảm bảo để được như vậy nếu không có yếu tố được thêm vào hoặc gỡ bỏ từ các từ điển giữa lần lặp đầu tiên và lần lặp lại cuối cùng? Đó là, tôi có thể giả định rằng thứ tự của mảng numpy được tạo ra ở mỗi lần lặp lại từ từ điển sẽ không thay đổi? Ví dụ: nếu từ điển có định dạng {'Glucose': 10, 'Fructose': 12}, nếu một Mảng được tạo từ từ điển này sẽ luôn là có cùng thứ tự (không quan trọng thứ tự đó là gì, như miễn là nó xác định).
Xin lỗi vì bài đăng lớn, tôi chỉ muốn cho bạn biết tôi đến từ đâu.
@ChinmayKanchi bạn có phiền không nếu tôi chỉnh sửa rất nhiều câu hỏi này? Tất cả các chi tiết về mạng lưới thức ăn và tích hợp ODEs không liên quan gì đến câu hỏi, đó là một câu hỏi rất hay và quan trọng. – LondonRob