def create_instance(ins): db_session = db.Session() ins = Instance(ins.get('image_id'),\ ins.get('user_id'), ins.get('container_name'),\ ins.get('container_serial'), ins.get('host'), \ ins.get('port'), ins.get('status'), ins.get('jump_server')) db_session.add(ins) db_session.commit()
def put(self, id): """Update an instance.""" instance = Instance.query.filter_by(id=id).first_or_404() app.logger.info('Update instance: %s' % id) target = Instance.from_json(request.data) instance.merge(target) db.session.commit() return instance.to_json()
def post(self, id): """Create an instance, expecting a json content.""" instance = Instance.from_json(request.data) app.logger.info('Creating new instance: %s' % request.data) db.session.add(instance) try: db.session.commit() except IntegrityError, error: app.logger.warning(error) abort(409)
def getInstance(region): ec2 = getResourceEc2(region) list = [] try: for instances in ec2.instances.all(): Instances = Instance.instance( instances.image.name, instances.platform, instances.instance_type, instances.public_dns_name, instances.state.get("Name"), instances.private_ip_address, instances.tags[0].get("Value"), instances.id, instances.key_name) list.append(Instances) return jsonify([ob.__dict__ for ob in list]) except ClientError as e: data = {"status": "fail", "message": "region not available"} response = app.response_class(status=404, response=json.dumps(data), mimetype='application/json') return response
def cmd_create(): """Creates (and starts) a new instance. """ instance = Instance() session.add(instance) session.commit() print "Creating new instance with id: %d" % instance.iid instance.setup() print "New instance created with id: %d" % instance.iid session.commit() instance.start() session.commit() print "Instance %s started on port %d" % (instance.iid, instance.port) return instance
man = pair[0] woman = pair[1] if worst_husband_list[woman.index].index == -1: worst_husband_list[woman.index] = man continue if woman.prefers(worst_husband_list[woman.index], man): worst_husband_list[woman.index] = man worst_pair_list = [(man.index, woman_index) for woman_index, man in enumerate(worst_husband_list)] worst_pair_list.sort() return worst_pair_list if __name__ == "__main__": random.seed(0) # GaleShapleyアルゴリズム実行 instance = Instance(7) gs_output = Algorithm.GaleShapley(instance) instance.show() print("Gale-Shapley出力") gs_output.show() assert(SMUtil.is_stable(instance, gs_output)) # 全探索で男性最良ペア、女性最悪ペアを計算 man_best_pair_list = Algorithm.calc_man_best_wife_pair(instance) print("男性最良ペア集合") for pair in man_best_pair_list: print("(" + str(pair[0]) + ", " + str(pair[1]) + ")", end=" ") print() woman_worst_pair_list = Algorithm.calc_woman_worst_husband_pair(instance) print("女性最悪ペア集合") for pair in woman_worst_pair_list:
for woman in instance.women: # 男性側に駆け落ちするインセンティブが存在 man_dissatisfaction = man.prefers(woman, matching.search_wife(man)) # 女性側に駆け落ちするインセンティブが存在 woman_dissatisfaction = woman.prefers(man, matching.search_husband(woman)) if man_dissatisfaction and woman_dissatisfaction: return False, (man, woman) return True, (Person(0, -1), Person(0, -1)) if __name__ == "__main__": random.seed(3) # create_all_matching のテスト instance_size = 8 instance = Instance(instance_size) matching_list = SMUtil.create_all_matching(instance) assert(len(matching_list) == math.factorial(instance_size)) print("show Matchings") for i, matching in enumerate(matching_list): matching.show() if i > 10: break # is_stable のテスト print("show Instance") instance.show() is_stable, blocking_pair = SMUtil.is_stable(instance, matching_list[0]) assert(is_stable is False) print(str(blocking_pair[0].index) + ", " + str(blocking_pair[1].index)) # => 1, 2 stable_matching_count = 0
def get_dimension_product(): instancia_opel_corsa = Instance("Opel Corsa", 2200) instancia_opel_adam = Instance("Opel Adam", 300) instancia_opel_astra = Instance("Opel Astra", 4000) instancia_opel_vectra = Instance("Opel Vectra", 2500) instancia_opel_vivaro = Instance("Opel Vivaro", 3500) instancia_mercedes_clasea = Instance("Mercedes Clase A", 2000) instancia_mercedes_claseb = Instance("Mercedes Clase B", 500) instancia_mercedes_clasee = Instance("Mercedes Clase E", 3000) instancia_mercedes_clases = Instance("Mercedes Clase S", 500) instancia_mercedes_vito = Instance("Mercedes Vito", 1500) instancia_bmw_serie1 = Instance("BMW Serie 1", 11000) instancia_bmw_serie2 = Instance("BMW Serie 2", 9000) instancia_bmw_serie3 = Instance("BMW Serie 3", 15000) instancia_bmw_serie5 = Instance("BMW Serie 5", 5000) jerarquia_producto = Hierarchy("Producto especifico", [ instancia_opel_corsa, instancia_opel_adam, instancia_opel_astra, instancia_opel_vectra, instancia_opel_vivaro, instancia_mercedes_clasea, instancia_mercedes_claseb, instancia_mercedes_clasee, instancia_mercedes_clases, instancia_mercedes_vito, instancia_bmw_serie1, instancia_bmw_serie2, instancia_bmw_serie3, instancia_bmw_serie5 ]) instancia_utilitario = Instance("Utilitario", 25000) instancia_compacto = Instance("Compacto", 30000) jerarquia_segmento = Hierarchy("Segmento", [instancia_utilitario, instancia_compacto]) instancia_industrial = Instance("Industrial", 5000) instancia_personal = Instance("Personal", 55000) jerarquia_tipo = Hierarchy("Tipo", [instancia_industrial, instancia_personal]) instancia_opel = Instance("Opel", 12500) instancia_mercedes = Instance("Mercedes", 7500) instancia_bmw = Instance("BMW", 40000) jerarquia_marca = Hierarchy( "Marca", [instancia_opel, instancia_mercedes, instancia_bmw]) grafo = GraphDAG() grafo.add_hierarchy(jerarquia_marca) grafo.add_hierarchy(jerarquia_tipo) grafo.add_hierarchy(jerarquia_segmento) grafo.add_hierarchy(jerarquia_producto) grafo.add_edge(jerarquia_marca, jerarquia_segmento) grafo.add_edge(jerarquia_marca, jerarquia_tipo) grafo.add_edge(jerarquia_tipo, jerarquia_producto) grafo.add_edge(jerarquia_segmento, jerarquia_producto) return Dimension("Producto", grafo)
def load(self): #Open file Dialog dialog = QFileDialog(None) dialog.setOption(QFileDialog.DontUseNativeDialog, True) content = "" if dialog.exec_(): fileName = dialog.selectedFiles()[0] f = open(fileName, "r+") content = f.read() f.close() #loads data from json-formated data data = json.loads(content) d = { "Wall": list(), "Tower": list(), "MainBody": list(), "Roof": list() } #Removes the current content in scene node = self.scene.find("test") try: node.detachNode() except: print("A generation result does not exist yet") # clears UI Model.clearLayout(self.window.modelLstLayout) Model.clearLayout(self.window.modelLstLayout2) #Creates a new model cluster dummy = NodePath("test") typeToInstances = dict() for key in d: parent = dummy.attachNewNode("Bodies") path = data.get(key).get("model") color = data.get(key).get("color") model = self.loader.loadModel(path) material = Material() material.setShininess(0.0) material.setAmbient((0.2, 0, 0, 1)) material.setDiffuse((color[0], color[1], color[2], color[3])) model.setMaterial(material) modelObj = Model(path, model, self) Model.showBase = self Model.allModels.append(modelObj) self.window.addModelUI(modelObj) locations = data.get(key).get("locations") scales = data.get(key).get("scale") rotations = data.get(key).get("rotation") for i in range(len(locations)): location = (locations[i][0], locations[i][1], locations[i][2]) scale = (scales[i][0], scales[i][1], scales[i][2]) rotation = (rotations[i][0], rotations[i][1], rotations[i][2]) instance = Instance(model, parent, location, rotation, scale=scale) instance.instantiate() instancies = typeToInstances.get(key, list()) instancies.append(instance) typeToInstances["Wall"] = instancies castle = Castle(typeToInstances, dummy, self.scene) self.castle = castle castle.instantiate()