本文整理汇总了Python中Model.Model.calculateEquilibrium方法的典型用法代码示例。如果您正苦于以下问题:Python Model.calculateEquilibrium方法的具体用法?Python Model.calculateEquilibrium怎么用?Python Model.calculateEquilibrium使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model.Model
的用法示例。
在下文中一共展示了Model.calculateEquilibrium方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_trial
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import calculateEquilibrium [as 别名]
def run_trial(size=11, graph_type='paper', pi=.5, phi=.5, delta=.5):
model = Model()
model.updatePi(pi)
model.updatePhi(phi)
model.updateDelta(delta)
model.updateSize(size)
typeFunctions = {'ER': model.graphErdosRenyi,
'BA': model.graphBarabasiAlbert,
'WS': model.graphWattsStrogatz,
'paper': model.graphPaperGraph,
'cool': model.graphCoolGraph}
typeFunctions[graph_type]
return sum(model.calculateEquilibrium()[0])
示例2: __init__
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import calculateEquilibrium [as 别名]
class Simulation:
def __init__(self):
handlers = {
'on_window1_destroy': Gtk.main_quit,
'erdosRenyi': self.erdosRenyi,
'barabasiAlbert': self.barabasiAlbert,
'wattsStrogatz': self.wattsStrogatz,
'paperGraph': self.paperGraph,
'changePi': self.changePi,
'changePhi': self.changePhi,
'changeDelta': self.changeDelta,
'changeSize': self.changeSize,
}
#Declare class properties and upload GUI
self.builder = Gtk.Builder()
self.model = Model()
self.builder.add_from_file(GUI_FILE)
self.builder.connect_signals(handlers)
def runSimulation(self):
window = self.builder.get_object(MAIN_WINDOW)
window.show_all()
self._refreshView()
Gtk.main()
def _refreshView(self):
#Write updated model to the img file
self.model.image.draw(IMG_FILE)
#Read the updated model from the img file to the GUI
graph_pic = self.builder.get_object('graph_image')
graph_pic.set_from_file(IMG_FILE)
totalCrime = self.builder.get_object('total_crime_label')
totalCrimeText = 'Total Crime Level: '
crimeLevels = self.model.calculateEquilibrium()[0]
print crimeLevels
totalCrime.set_text(totalCrimeText + "{:.3f}".format(sum(crimeLevels)[0]))
print crimeLevels
#Update average crime measure
averageCrime = self.builder.get_object('average_crime_label')
averageCrimeText = 'Average Crime Level: '
averageCrime.set_text(averageCrimeText + "{:.3f}".format(sum(crimeLevels)[0]/self.model.size))
#Update Key Player
keyPlayer = self.builder.get_object('key_player_label')
keyPlayerText = 'Key Player is Identified as '
keyPlayerValue = self.model.identifyKeyPlayer()
keyPlayer.set_text(keyPlayerText + keyPlayerValue[1] + ' with x_i = ' + "{:.3f}".format(crimeLevels[int(keyPlayerValue[1])][0]))
keyLink = self.builder.get_object('key_link_label')
keyLinkText = 'Key Link is Identified as '
keyLinkValue = self.model.calculateMaxLink()
keyLink.set_text(keyLinkText + str(keyLinkValue))
return 0
def erdosRenyi(self, button):
self.model.graphErdosRenyi()
self._refreshView()
return 0
def barabasiAlbert(self, button):
self.model.graphBarabasiAlbert()
self._refreshView()
return 0
def wattsStrogatz(self, button):
self.model.graphWattsStrogatz()
self._refreshView()
return 0
def paperGraph(self, button):
self.model.graphPaperGraph()
self._refreshView()
return 0
def changePi(self, button):
scale = self.builder.get_object("pi_scale")
value = scale.get_value()
self.model.updatePi(value)
self._refreshView()
return 0
def changePhi(self, button):
scale = self.builder.get_object("phi_scale")
value = scale.get_value()
self.model.updatePhi(value)
self._refreshView()
return 0
def changeDelta(self, button):
scale = self.builder.get_object("delta_scale")
value = scale.get_value()
self.model.updateDelta(value)
self._refreshView()
return 0
#.........这里部分代码省略.........