def produce(self, product_id, price, quality): # если норм по капиталам, себестоимости и производственным мощностям, то вперёд if (price > self.cost) and (quality <= self.max_quality) and (self.check() == 0): self.price = price return product.product(id=product_id, quality=quality, price=price) else: self.price = -10000 return product.product(id=-1)
def test_duplicates(): assert list(product([[2, 2], [2, 2]])) == [ (2, 2), (2, 2), (2, 2), (2, 2), ]
def dm_init(name): dm_url = { "LG0": "https://www.dm.de/aptamil-pronutra-pre-von-geburt-an-p4056631001202.html", "LG1": "https://www.dm.de/aptamil-pronutra-anfangsmilch-1-von-geburt-an-p4056631001226.html", "LG2": "https://www.dm.de/aptamil-pronutra-folgemilch-2-nach-dem-6-monat-p4056631001240.html", "LG3": "https://www.dm.de/aptamil-pronutra-folgemilch-3-ab-dem-10-monat-p4008976022343.html", "ZH1": "https://www.dm.de/aptamil-pronutra-kindermilch-ab-1-jahr-p4008976022985.html", "ZH2": "https://www.dm.de/aptamil-kindermilch-ab-2-jahren-p4008976022992.html", "BJ0": "https://www.dm.de/aptamil-profutura-anfangsmilch-pre-von-geburt-an-p4008976022923.html", "BJ1": "https://www.dm.de/aptamil-profutura-anfangsmilch-1-p4008976022909.html", "BJ2": "https://www.dm.de/aptamil-profutura-folgemilch-2-nach-dem-6-monat-p4008976022916.html" } dm_lst = [] for i in name: milk = product() milk.setName(name_ch[i]) milk.setUrl(dm_url[i]) dm_lst.append(milk) return dm_lst
def testFloats(self): for x in range(-10, 10): for y in range(-10, 10): x = x / 10.0 y = y / 10.0 p = product.product(x, y) self.failUnless(p == x * y, 'Float multip;ication failed')
def consume(self, products): # возвращать будем продукт fun_result = product.product(id=-1) available_product_lst = [] # цикл для фильтрации тех, что не карману for pr in products: if self.money >= pr.price: available_product_lst.append(pr) best_price = max_price best_qv = min_qv # цикл поиска лучшего качества for pr in available_product_lst: if pr.quality >= best_qv: best_qv = pr.quality product_qv_lst = [] # сбор всех продуктов лучшего качества for pr in available_product_lst: if pr.quality == best_qv: product_qv_lst.append(pr) # выбор из них тех, что дешевле for pr in product_qv_lst: if pr.price <= best_price: best_price = pr.price # вывод продукта с лучшими характеристиками for pr in product_qv_lst: if pr.price == best_price: fun_result = pr break return fun_result
def newRec(self, code=0, name='', typel='', material=None, weight=0, price=0): self.appendList(product(code, name, typel, material, weight, price))
def factorial(n): result=[] if n==0: return 1 else: for idx in range(1,n+1): result.append(idx) return product.product(result)
def display_page(pathname): if pathname == '/trends': return trends() if pathname == "/survey": return contribute() if pathname == "/about": return about() return product()
def test_one_float_and_one_int(self): """ product(1.3, 10) should return 13 need to use AlmostEqual because of floating point precision after several decimal places!!! """ self.assertAlmostEqual(product(1.3, 10), 13)
def test_product(): assert product([5, 4, 1, 3, 9]) == 540 assert product([-2, 6, 7, 8]) == -672 assert product([10]) == 10 assert product([0, 2, 9, 7]) == 0 assert product(None) is None assert product([]) is None
def main(): #calling the inventory functions from the class inventory1 = inventory("1", "Jacket", "12", "$59.95") print(inventory1) print() #the spacing on this constructor helps shape it when it is printed #storing 4 arguments into the three variables Product1 = product(" 1 ", "Jacket ", " 12 ", " $59.95 ") Product2 = product(" 2 ", "Designer Jeans ", " 40 ", " $34.95 ") Product3 = product(" 3 ", "Shirt ", " 20 ", " $24.95 ") print(" ID: " + " Desription: " + "Quantity: " + "Price: ") print(Product1) print() print(Product2) print() print(Product3)
def test_product(): assert list(product([[0, 1, 2], [0, 1, 2]])) == [ (0, 0), (0, 1), (1, 0), (0, 2), (1, 1), (2, 0), (1, 2), (2, 1), (2, 2), ] assert list(product([[0, 1, 2], [0, 1, 2]], key=sqrt)) == [ (0, 0), (0, 1), (1, 0), (0, 2), (2, 0), (1, 1), (1, 2), (2, 1), (2, 2), ] assert list(product([[0, 1, 2], [0, 1, 2]], key=lambda i: i**2)) == [ (0, 0), (0, 1), (1, 0), (1, 1), (0, 2), (2, 0), (1, 2), (2, 1), (2, 2), ]
def getPrice(search): searchURL = 'http://www.newegg.com/Product/ProductList.aspx?Submit=ENE&DEPA=0&Order=BESTMATCH&N=-1&isNodeId=1&Description='+ str(search) +'&x=-852&y=-112' try: newegg = urllib2.urlopen(searchURL) except: raise newegg_content = newegg.read().replace('\n','') newegg_content = newegg_content.replace('\t','') # file = open('newegg.html', 'w') # file.write(newegg_content) modelList = [] items = re.findall(r'\<div class="itemCell"(.*?)\<br class="clear"', newegg_content) for item in items: p = product() #print item + '\n' url = re.findall(r'\<a href="(.*?)"',item) if len(url) > 0: p.url = url[0] # p.url = p.url.encode('utf8') name = re.findall(r'\<span class="itemDescription" id="titleDescription.*?\>(.*?)</span>',item) if len(name) > 0: p.name = name[0] price = re.findall(r'\<input type="hidden" name="priceBefore" value="\$([,0-9\.]+?)"',item) if len(price) > 0: p.price = float(filter(lambda x : x not in ',', price[0])) else: p.price = None p.source = '/images/newegg-logo.jpg' # Get the product photo imgurl = re.findall(r'\<div class="itemGraphics"\>.*?src="(.*?)"', item) if len(imgurl) > 0: imgurl = imgurl[0] p.imgurl = imgurl else: p.imgurl = p.source modelList.append(p) # html = '<li><a href="' + p.url + '">' + p.name + '</a><br>' + p.price + '<br>Newegg</li>' # file.write(html) # file.close() newegg.close() return modelList
def rossmannInit(name): rossmann_url = {"LG0": "https://www.rossmann.de/produkte/aptamil/pronutra-advance-pre-anfangsmilch-von-geburt-an/4056631001202.html", "LG1": "https://www.rossmann.de/produkte/aptamil/pronutra-advance-1-anfangsmilch-von-geburt-an/4056631001226.html", "LG2": "https://www.rossmann.de/produkte/aptamil/pronutra-advance-2-folgemilch-nach-dem-6-monat/4056631001240.html", "LG3": "https://www.rossmann.de/produkte/aptamil/pronutra-advance-3-folgemilch-ab-dem-10-monat/4056631001264.html", "ZH1": "https://www.rossmann.de/produkte/aptamil/pronutra-kindermilch-1/4008976022985.html", "ZH2": "https://www.rossmann.de/produkte/aptamil/pronutra-kindermilch-2/4008976022992.html", "BJ0": "https://www.rossmann.de/produkte/aptamil/profutura-pre-anfangsmilch-von-geburt-an/4056631001301.html", "BJ1": "https://www.rossmann.de/produkte/aptamil/profutura-1-anfangsmilch-von-geburt-an/4056631001325.html", "BJ2": "https://www.rossmann.de/produkte/aptamil/profutura-2-folgemilch-nach-dem-6-monat/4056631001349.html"} rm_lst = [] for i in name: milk = product() milk.setName(name_ch[i]) milk.setUrl(rossmann_url[i]) rm_lst.append(milk) return rm_lst
def scrape_product(nextPage, i=1): categories = get_categories(nextPage) x = "continue" while x == "continue": source1 = requests.get(nextPage).text soup = BeautifulSoup(source1, "lxml") i += 1 actual_page = soup.find("a", class_="disabledLink") try: prox_page = str(int(actual_page.text) + 1) nextPage = ( "https://www.cotodigital3.com.ar" + soup.find("a", title=str("Ir a página " + prox_page)).attrs["href"] ) except: x = "stop" print("no next") li = soup.findAll("li", class_="clearfix") for each in li: producto = each.find("div", class_="descrip_full").text.strip() try: price = ( each.find("span", class_="atg_store_newPrice") .text.split("$")[1] .strip() ) except: price = 0 sku = ( each.find("div", class_="descrip_full") .attrs["id"] .split("sku")[1] .strip() ) insert_product( product( categories[0], categories[1], categories[2], sku, producto, price ) ) return
def reweInit(name): rewe_url = {"LG0": "https://shop.rewe.de/PD1958158?variantArticleId=4008976022350", "LG1": "https://shop.rewe.de/PD1958156?variantArticleId=4008976022329", "LG2": "https://shop.rewe.de/PD1958154?variantArticleId=4008976022336", "LG3": "https://shop.rewe.de/PD1958152?variantArticleId=4008976022343", "ZH1": "https://shop.rewe.de/PD1964189?variantArticleId=4008976022985", "ZH2": "https://shop.rewe.de/PD1964191?variantArticleId=4008976022992", "BJ0": "https://shop.rewe.de/PD2522946?variantArticleId=4008976022923", "BJ1": "https://shop.rewe.de/PD2522955?variantArticleId=4008976022909", "BJ2": "https://shop.rewe.de/PD2522960?variantArticleId=4008976022916", } rewe_lst = [] for i in name: milk = product() milk.setName(name_ch[i]) milk.setUrl(rewe_url[i]) rewe_lst.append(milk) return rewe_lst
def totient(num): """ Counts the numbers that are relative prime to the number. This means that if a number 'x' has common divisors with another number 'a' lower than itself, it is, 'a' is not relative prime to 'x'. This means that if a number is prime, its totient function is its value - 1, as all numbers lower than the number itself are relative prime to the number. An example: totient(9): 1, 2, 4, 5, 7, 8 are all relative prime 3, 6, and 9 have at least one common divisor with 9 returns 6, as there are 6 numbers relative prime to 9 If you visit 'https://en.wikipedia.org/wiki/Euler%27s_totient_function' this function uses the function described under euler's product formula. """ # set(prime_factors(num)) to get only unique primes. # it is the (1 - 1/p) part from the wiki-page uniqe_primes = [(1 - 1 / p) for p in set(prime_factors(num))] phi = num * product(uniqe_primes) # The totient function is commonly called phi phi = int(round(phi)) # As phi is a whole number return phi
def scan_items(self, some_product): temp = int(0) for pro_data in range(len(self.storing_products)): if self.storing_products[pro_data][0].__contains__(some_product): # store the items into the product list data_in_list = product.product( self.storing_products[pro_data][0], self.storing_products[pro_data][1], self.storing_products[pro_data][2], self.storing_products[pro_data][3]) self.bucket.append(data_in_list) self.price_of_products += float( self.storing_products[pro_data][3]) temp = 1 print(self.storing_products[pro_data][1] + ", " + self.storing_products[pro_data][2] + " - $" + self.storing_products[pro_data][3]) break self.temp_pro_amount = self.price_of_products if temp == 0: print("This product does not exists in our inventory.")
def getProductInfo(url,headers2): data=requests.get(url,headers=headers2).text soup=BeautifulSoup(data,"lxml") productTitle =soup.select("#J_Property > h1") productSeller =soup.select("#J_SellerInfo > div.simple > div.wangwang > a") price= soup.select("#J_Property > ul.price-info > li:nth-of-type(1) > span.price.big > em") costPrice=soup.select("#J_Property > ul.price-info > li:nth-of-type(2) > span:nth-of-type(2)") productCondition=soup.select("#J_Property > ul.idle-info > li:nth-of-type(1) > em") adders=soup.select("#J_Property > ul.idle-info > li:nth-of-type(2) > em") particulars=soup.select("#J_DescContent") flow=soup.select("#J_Browse") date=soup.select("#idle-detail > div.top-nav.clearfix > div.others-wrap > ul > li:nth-of-type(2) > span") title = productTitle if len(productTitle) == 0 else productTitle[0].get_text() seller = productSeller[0].get_text() price = price[0].get_text() cost = costPrice if len(costPrice) == 0 else costPrice[0].get_text() condition = productCondition[0].get_text() adder = adders[0].get_text() particular = getParticular(particulars[0].get("data-url")) flow = getFlow(flow[0].get("data-url")) date = date[0].get_text() return product(title,seller,price,cost,condition,adder,particular,flow,date)
def getPrice(search): searchURL = 'http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Daps&field-keywords=' + str(search) #print searchURL try: amazon = urllib2.urlopen(searchURL) except: raise amazon_content = amazon.read().replace('\n', '') # file = open('amazon.html', 'w') # file.write(amazon_content) modelList = [] items = re.findall(r'\<div class="result product"(.*?)\<br clear', amazon_content) # print len(items) for i in range(len(items)): item = items[i] p = product() # print i+1 #print item url = re.findall(r'\<div class="productTitle".*?href="(.*?)"\>', item) if len(url) > 0: url = url[0] p.url = url # p.url = p.url.encode('utf8') name = re.findall(r'\<div class="productTitle".*?href=".*?"\>(.*?)\</a\>', item) if len(name) > 0: name = name[0] p.name = name # print name price = re.findall(r'\<div class="newPrice"\>.*?\<span\>.*?\$([,0-9\.]+?)\</span\>', item) if len(price) > 0: price = price[0] p.price = float(filter(lambda x : x not in ',', price)) else: price = re.findall(r'\<div class="subPrice"\>.*?\<span\>.*?\$([,0-9\.]+?)\</span\>', item) if len(price) > 0: price = price[0] p.price = float(filter(lambda x : x not in ',', price)) else: p.price = None # print price #model = re.findall(r'\<strong itemprop="model"\>(.*?)\</strong\>', item)[0] p.source = '/images/amazon-logo.jpg' # Get the product photo imgurl = re.findall(r'\<div class="productImage".+?src="(.*?)"', item) if len(imgurl) > 0: imgurl = imgurl[0] p.imgurl = imgurl else: p.imgurl = p.source #p.model = model modelList.append(p) # html = '<li><a href="' + p.url + '">' + p.name + '</a><br>$' + str(p.price) + '<br>Amazon</li>' # file.write(html) # print p.name, '\n' # print p.url, '\n' # print p.price, '\n' # print '\n' # print amazon_content # file.write(amazon_content) # file.close() return modelList amazon.close()
K = len(demand_possibility[0]) # scenario number in a period S = K**T # total scenario number # set values for scenario links: whether scenario i links with scenario j in period t scenarioLink = [[[0 for s in range(S)] for s in range(S)] for t in range(T)] for t in range(T): slices = round(S * (1 / K)**(t + 1)) # number of scenario in a slice slice_num = round(K**(t + 1)) # totoal number of slices for i in range(slice_num): for j in range(slices * i, slices * (i + 1)): for k in range(slices * i, slices * (i + 1)): scenarioLink[t][j][k] = 1 # set values for scenario probabilities scenario_permulations = product.product(range(K), T) scenario_probs = [0 for s in range(S)] scenario_values = [0 for s in range(S)] for s in range(S): index = scenario_permulations[s][0] scenario_probs[s] = demand_possibility[0][index] for i in range(1, len(scenario_permulations[s])): index = scenario_permulations[s][i] index2 = booming_demand[i] scenario_probs[ s] = scenario_probs[s] * demand_possibility[index2][index] # compute value of perfect information: final_value for s in range(S): mean_demand = [[[0 for i in range(N)] for j in range(2)] for t in range(T)] for n in range(N):
def getPrice(search): # testing output # file = open('bestbuy.html', 'w') # result product list for return pList = [] # Bestbuy's search URL searchURL = 'http://www.bestbuy.com/site/searchpage.jsp?_dyncharset=ISO-8859-1&_dynSessConf=ATG12474449190&id=pcat17071&type=page&sc=Global&cp=1&nrp=15&sp=&qp=&list=n&iht=y&usc=All+Categories&ks=960&saas=saas&st=%s' % search try: bestbuy = urllib2.urlopen(searchURL) except: raise # Get the content and eliminate the \n so we can use regex bestbuy_content = bestbuy.read().replace('\n', '') # find all the product divs and store in a list items = re.findall(r'\<div class="hproduct"(.*?)itemprop="description"', bestbuy_content) # For each product, we build out product object for i in range(len(items)): item = items[i] p = product() # print i # print item url = re.findall(r'\<a.*?rel="product" href="(.*?)"', item) if len(url) > 0: url = url[0] p.url = 'http://www.bestbuy.com' + url # p.url = p.url.encode('utf8') name = re.findall(r'\<h3.*\>\<a.*?rel="product".*?\>(.*?)\</a\>', item) if len(name) > 0: name = name[0] p.name = name price = re.findall(r'\<h4 class="price sale"\>.*?\$([,0-9\.]+).*?\</h4\>', item) if len(price) > 0: price = price[0] p.price = float(filter(lambda x : x not in ',', price)) else: p.price = None model = re.findall(r'\<strong itemprop="model"\>(.*?)\</strong\>', item) if len(model) > 0: p.model = model[0] # build our product object # print name # print price p.source = '/images/bestbuy-logo.jpg' # Get the product photo imgurl = re.findall(r'\<img itemprop="image".*?src="(.*?)"', item) if len(imgurl) > 0: imgurl = imgurl[0] p.imgurl = imgurl else: p.imgurl = p.source # add to list pList.append(p) # html = '<li><a href="' + p.url + '">' + p.name + '</a><br>' + p.price + '<br>' + p.model + '</li>' # file.write(html) # print p.name, '\n' # print p.url, '\n' # print p.price, '\n' # print '\n' # print bestbuy_content # file.write(bestbuy_content) # file.close() bestbuy.close() return pList
def test_two_positive_integers(self): """ product(2,3) should return 6 """ self.assertEqual(product(2,3), 6)
from gantt import * def colonne( liste, j ): ## fonction pour avoir la colonne j+1 d'une matrice (liste de listes) return [item[j] for item in liste] start_time = time.time() mfab = 3 lin = 2 netmin = [0.5, 1] netmaj = [4, 16] #on définit les produit prod1 = product('produit1', [3, 5, 3, 16, 0], 16, 2, 0, 0, 1) prod2 = product('produit2', [3, 5, 3, 21, 0], 21, 3, 0, 0, 1) prod3 = product('produit3', [3, 5, 3, 22, 22], 22, 2, 0, 0, 1) prod4 = product('produit4', [3, 5, 3, 0, 15], 15, 1, 0, 0, 1) prod5 = product('produit5', [3, 5, 3, 0, 24], 24, 46, 0, 0, 23) prod6 = product('produit1', [3, 5, 3, 16, 0], 16, 46, 0, 0, 46) prod = [prod1, prod2, prod3, prod4, prod5, prod6] jssp = instance(mfab, lin, netmin, netmaj, prod) jssp.process_input() sol_const = construct_sol(jssp) sol_const.greedy() sol = solution(jssp, sol_const.X, sol_const.Y, sol_const.U) sol.decode() print("Y =", sol.Y)
def test_two_negative_integers(self): """ product(-2, -3) should return 6 """ self.assertEqual(product(-2,-3), 6)
NAMES = [] PROD = [] print('run',this_simname) #p_tc_raw = product.product('Tc_raw',fname='%s/data_small/%s_ct.h5'%(basedir,this_simname),field='collapse_times',style='value',width=400) #p_tc_raw_log = product.product('Log Tc_raw',fname='%s/data_small/%s_mean_collapse_log.h5'%(basedir,this_simname),field='collapse_times',style='value',width=400,number_format="%0.2f") #p_distance = product.product('Log Distance to Next',fname='%s/data_small/%s_neighbors_distance_0_log.h5'%(basedir,this_simname),field='distance_0',style='value',width=400,number_format='%0.2f') #p_mean_density = product.product('Log Core Density',fname='%s/data_small/%s_neighbors_mean_density_log.h5'%(basedir,this_simname),field='mean_density',style='value',width=400, number_format='%0.2f') #u05_neighbors_distance_0.h5 #u05_neighbors_mean_density.h5 p_peak_density = product.product('Peak Density',fname="browser_data/%s_mountain_top.h5"%this_simname, field='peak_density',style='value_target_file',width=400) p_nparticles = product.product('Nparticles',fname="browser_data/u50%d_nparticles.h5"%nsim, field='n_particles',style='value') p_neighbor = product.product('Neighborhood',fname="browser_data/neighborhood_by_core_u50%d.h5"%nsim, field='neighborhood',style='value',number_format='%d') PROD.append(p_peak_density) PROD.append(p_nparticles) PROD.append(p_neighbor) NAMES.append("mountain top") RE.append(r"/*mountain_tops/%s/mountain_top_%s_c(\d\d\d\d)_Projection_x_density.png"%( this_simname, this_simname)) NAMES.append('GE mass') RE.append(r"/*ge_cuml/u50%d/u50%d_cuml_c(\d\d\d\d).png"%(nsim,nsim)) NAMES.append("mountain rings")
def test_multiplies_numbers_1(self): # Failure message: # expected product(2, 2) to equal 4 self.assertEqual(product(2, 2), 4)
def main1(): print("***LOGIN***") a = login.login() b = staff.staff() c = product.product() d = billing.product1() while (1): print("1.login 2.set password") a1 = int(input("enter your choice:>")) if (a1 == 1): a.login1() break if (a1 == 2): a.setpassword() continue else: print("try again") while (1): print("1.staff details 2.product details 3.billing 4.exit") a2 = int(input("enter your choice:>")) if (a2 == 1): b.print_details() continue if (a2 == 2): while (1): print("1.product search") print("2.add product") print("3.update price") print("4.update quantity") print("5.quit") a3 = int(input('enter your choice:>')) if (a3 == 1): c.product_search() continue if (a3 == 2): c.add_product() continue if (a3 == 3): c.update_price() continue if (a3 == 4): c.update_quantity() continue if (a3 == 5): break else: continue if (a2 == 3): while (1): print("1.buy product") print('2.quit') a4 = int(input("enter your choice:>")) if (a4 == 1): d.buy_product() continue if (a4 == 2): break else: continue if (a2 == 4): quit() else: print("wrong choice")
from go import * import product reload(product) import make_page reload(make_page) basedir = '/Users/dcollins/RESEARCH3/Paper19_47_overlap/0000_main_plots/' basedir = '/Users/dcollins/RESEARCH3/Paper19_47_overlap/0000_main_plots/' glob1 = "%s/density_radius/density_radius_c????.png" % basedir reg1 = re.compile(r"%s/density_radius/density_radius_c(\d\d\d\d).png" % basedir) p1 = product.product('rho_r', regexp=reg1, myglob=glob1, parameters=['core_id'], style='single', width=400) p1.get_frames() glob1 = "%s/core_proj_follow/density_radius_c????.png" % basedir glob2 = r"%s/core_proj_follow/follow_c????_n????_centered_Projection_x_density.png" % ( basedir) reg2 = re.compile( r"%s/core_proj_follow/follow_c(\d\d\d\d)_n(\d\d\d\d)_centered_Projection_x_density.png" % (basedir)) p2 = product.product('core_proj_follow', regexp=reg2, myglob=glob2, parameters=['core_id', 'frame'], style='frames', width=400) #p2.check_glob()
#sim_list=['u301'] for this_simname in sim_list: print('run', this_simname) #p_tc_raw = product.product('Tc_raw',fname='%s/data_small/%s_ct.h5'%(basedir,this_simname),field='collapse_times',style='value',width=400) #p_tc_raw_log = product.product('Log Tc_raw',fname='%s/data_small/%s_mean_collapse_log.h5'%(basedir,this_simname),field='collapse_times',style='value',width=400,number_format="%0.2f") #p_distance = product.product('Log Distance to Next',fname='%s/data_small/%s_neighbors_distance_0_log.h5'%(basedir,this_simname),field='distance_0',style='value',width=400,number_format='%0.2f') #p_mean_density = product.product('Log Core Density',fname='%s/data_small/%s_neighbors_mean_density_log.h5'%(basedir,this_simname),field='mean_density',style='value',width=400, number_format='%0.2f') #u05_neighbors_distance_0.h5 #u05_neighbors_mean_density.h5 p_peak_density = product.product( 'Peak Density', fname="datasets_small/%s_mountain_tops_take_9.h5" % this_simname, field='peak_density', style='value_target_file', width=400) r_mountain = r"%s/mountain_tops/%s/%s_peak_p(\d\d\d\d)_34_Projection_x_density.png" % ( basedir, this_simname, this_simname) p_mountain = product.product("mountain top", regexp=r2, parameters=['core_id'], style='single', width=400) p_mountain.get_frames() r_density = r"%s/density_time/%s/%s_density_6_c(\d\d\d\d).png" % ( basedir, this_simname, this_simname) p_density = product.product("density time",
def test_product(self): self.assertEqual(product.product([1, 2], [3, 4]), '(1, 3) (1, 4) (2, 3) (2, 4)')
def run(iterables): list(product(iterables))
from go import * import product reload(product) import make_page reload(make_page) basedir = '/Users/dcollins/RESEARCH3_USE_R4/Paper19_47_overlap/0000_main_plots/' glob1 = "%s/density_radius/density_radius_c????.png" % basedir reg1 = re.compile(r"%s/density_radius/density_radius_c(\d\d\d\d).png" % basedir) p1 = product.product('rho_r', regexp=reg1, myglob=glob1, parameters=['core_id'], style='single', width=400) p1.get_frames() glob1 = "%s/core_proj_follow/density_radius_c????.png" % basedir glob2 = r"%s/core_proj_follow/follow_c????_n????_centered_Projection_x_density.png" % ( basedir) reg2 = re.compile( r"%s/core_proj_follow/follow_c(\d\d\d\d)_n(\d\d\d\d)_centered_Projection_x_density.png" % (basedir)) p2 = product.product('core_proj_follow', regexp=reg2, myglob=glob2, parameters=['core_id', 'frame'], style='frames', width=400)
from product import product from jssp_instance import instance from construct_heurstic import construct_sol from solution import solution from tabu_new import tabu_serach import time start_time = time.time() mfab = 3 n = 6 lin = 2 netmin = [0.5, 1] netmaj = [4, 16] jssp = [] prod1 = product("Produit1", [3, 5, 3, 32, 0], 32, 1, 14, 14, 1) prod2 = product("Produit2", [3, 5, 3, 42, 0], 42, 1, 6, 6, 1 ) prod3 = product("Produit3", [3, 5, 3, 44, 44], 44, 1, 0, 0, 1) prod4 = product("Produit4", [3, 5, 3, 0, 30], 30, 1, 0, 0, 1) prod5 = product("Produit5", [3, 5, 3, 0, 48], 48, 1, 0, 0, 1) prod6 = product("Produit6", [3, 5, 3, 32, 0], 32, 1, 0, 0, 1) prod = [prod1, prod2, prod3, prod4,prod5,prod6] jssp = instance(mfab, lin, netmin, netmaj, prod) jssp.process_input() print("b=", jssp.b) print("g=", jssp.g) print("fab=", jssp.fab) print("con=", jssp.con) sol_const = construct_sol(jssp) sol_const.greedy()
try: return int(value) except: return value @signature.setter def signature(self, value): self.builder.tkvariables["signature"].set(value) if __name__ == '__main__': colorama.init() if len(sys.argv) > 1 and sys.argv[1] == "product": signer = product() modulo = 1014265245160156964 bounds = 2**60, 2**64 else: signer = addition() modulo = 4386756709 bounds = 2**32, 2**40 app = MyApplication(signer, bounds) app.modulo = modulo ready = False while not ready: try: app.makeKeys() except ValueError as e:
def test_one_postive_and_one_negative_integer(self): """ product(2, -3) should return -6 """ self.assertEqual(product(2,-3), -6)
def select_mip(scenario_selected, demand_scenarios, demand_possibility, booming_demand, T, delay_length): K = len(demand_possibility[0]) # scenario number in a period M = len(scenario_selected) # total selected scenario number S = K**T # total scenario number N = len(demand_scenarios[0]) # number of items # parameter values ini_I = [0, 0, 0] prices = [189, 144, 239] vari_costs = [140, 70, 150] ini_cash = 20000 overhead_cost = [2 * i for i in overhead_cost] discount_rate = 0.003 B = 10000 # total quantity of order loan ro = 0.015 # loan rate MM = 10000 scenario_permulations = product.product(range(K), T) scenario_select_detail = [[0 for t in range(T)] for i in range(M)] index = 0 for i in scenario_selected: scenario_select_detail[index] = scenario_permulations[i] index = index + 1 # set values for scenario links: whether scenario i links with scenario j in period t # should be checked and revised scenarioLink = [[[0 for s in range(M)] for s in range(M)] for t in range(T)] for t in range(T): for i in range(M): for j in range(M): if t == 0: if scenario_select_detail[i][t] == scenario_select_detail[ j][t]: scenarioLink[t][i][j] = 1 else: if scenarioLink[t - 1][i][j] == 1 and \ scenario_select_detail[i][t] == scenario_select_detail[j][t]: scenarioLink[t][i][j] = 1 # set values for scenario probabilities scenario_probs = [0 for s in range(M)] for s in range(M): index = scenario_permulations[scenario_selected[s]][0] scenario_probs[s] = demand_possibility[booming_demand[0]][index] for i in range(1, len(scenario_permulations[scenario_selected[s]])): index = scenario_permulations[scenario_selected[s]][i] scenario_probs[s] = scenario_probs[s] * demand_possibility[ booming_demand[i]][index] scenario_probs_all = [0 for s in range(S)] for s in range(S): index = scenario_permulations[s][0] scenario_probs_all[s] = demand_possibility[booming_demand[0]][index] for i in range(1, len(scenario_permulations[s])): index = scenario_permulations[s][i] scenario_probs_all[s] = scenario_probs_all[s] * demand_possibility[ booming_demand[i]][index] # add probability d = [[0 for s in range(S)] for s in range(S)] for i in range(S): for j in range(i, S): for k in range(len(scenario_permulations[0])): d[i][j] += (scenario_permulations[i][k] - scenario_permulations[j][k])**2 d[i][j] = math.sqrt(d[i][j]) d[j][i] = d[i][j] for i in range(S): if i not in scenario_selected: min_d = 1000000 min_index = 0 for j in range(M): if d[i][scenario_selected[j]] < min_d: min_d = d[i][scenario_selected[j]] min_index = j scenario_probs[ min_index] = scenario_probs[min_index] + scenario_probs_all[i] try: # Create a new model m = Model("select-scenario-mip") # Create variables Q = [[[m.addVar(vtype=GRB.CONTINUOUS) for s in range(M)] for n in range(N)] for t in range(T) ] # ordering quantity in each period for each product I = [[[m.addVar(vtype=GRB.CONTINUOUS) for s in range(M)] for n in range(N)] for t in range(T) ] # end-of-period inventory in each period for each product delta = [[[m.addVar(vtype=GRB.BINARY) for s in range(M)] for n in range(N)] for t in range(T)] # whether lost-sale not occurs C = [[LinExpr() for s in range(M)] for t in range(T)] # LinExpr, end-of-period cash in each period R = [[[LinExpr() for s in range(M)] for n in range(N)] for t in range(T + delay_length) ] # LinExpr, revenue for each product in each period # revenue expression for s in range(M): for n in range(N): for t in range(T + delay_length): if t < delay_length: R[t][n][s] = LinExpr(0) else: if t == delay_length: R[t][n][s] = prices[n] * ( ini_I[n] + Q[t - delay_length][n][s] - I[t - delay_length][n][s]) else: R[t][n][s] = prices[n] * ( I[t - delay_length - 1][n][s] + Q[t - delay_length][n][s] - I[t - delay_length][n][s]) m.update() # cash flow revenue_total = [[LinExpr() for t in range(T)] for s in range(M)] vari_costs_total = [[LinExpr() for t in range(T)] for s in range(M)] expect_revenue_total = [LinExpr() for t in range(T)] expect_vari_costs_total = [LinExpr() for t in range(T)] for s in range(M): for t in range(T): revenue_total[s][t] = sum([R[t][n][s] for n in range(N)]) vari_costs_total[s][t] = sum( [vari_costs[n] * Q[t][n][s] for n in range(N)]) if t == 0: C[t][s] = ini_cash + revenue_total[s][ t] - vari_costs_total[s][t] - overhead_cost[t] else: C[t][s] = C[t - 1][s] + revenue_total[s][ t] - vari_costs_total[s][t] - overhead_cost[t] for t in range(T): expect_revenue_total[t] = sum( [revenue_total[s][t] * scenario_probs[s] for s in range(M)]) expect_vari_costs_total[t] = sum( [vari_costs_total[s][t] * scenario_probs[s] for s in range(M)]) m.update() # objective function discounted_cash = [LinExpr() for s in range(M)] for s in range(M): for n in range(N): for k in range(delay_length): discounted_cash[s] = discounted_cash[s] + R[ T + k][n][s] / (1 + discount_rate)**(k + 1) final_cash = sum([ scenario_probs[s] * (C[T - 1][s] + discounted_cash[s]) for s in range(M) ]) expect_discounted_cash = sum( [scenario_probs[s] * (discounted_cash[s]) for s in range(M)]) # Set objective m.update() m.setObjective(final_cash, GRB.MAXIMIZE) # Add constraints # inventory flow for s in range(M): for n in range(N): for t in range(T): index = scenario_permulations[s][t] index2 = booming_demand[t] if t == 0: m.addConstr(I[t][n][s] <= ini_I[n] + Q[t][n][s] - demand_scenarios[index2][n][index] + (1 - delta[t][n][s]) * MM) m.addConstr(I[t][n][s] >= ini_I[n] + Q[t][n][s] - demand_scenarios[index2][n][index] - (1 - delta[t][n][s]) * MM) m.addConstr(ini_I[n] + Q[t][n][s] - demand_scenarios[index2][n][index] <= delta[t][n][s] * MM - 0.1) m.addConstr( ini_I[n] + Q[t][n][s] >= demand_scenarios[index2][n][index] - (1 - delta[t][n][s]) * MM) else: m.addConstr(I[t][n][s] <= I[t - 1][n][s] + Q[t][n][s] - demand_scenarios[index2][n][index] + (1 - delta[t][n][s]) * MM) m.addConstr(I[t][n][s] >= I[t - 1][n][s] + Q[t][n][s] - demand_scenarios[index2][n][index] - (1 - delta[t][n][s]) * MM) m.addConstr(I[t - 1][n][s] + Q[t][n][s] - demand_scenarios[index2][n][index] <= delta[t][n][s] * MM - 0.1) m.addConstr( I[t - 1][n][s] + Q[t][n][s] >= demand_scenarios[index2][n][index] - (1 - delta[t][n][s]) * MM) m.addConstr(I[t][n][s] <= delta[t][n][s] * MM) # m.computeIIS() # this function is only for infeasible model # m.write("model.ilp") # cash constraint for s in range(M): for t in range(T): if t == 0: m.addConstr( ini_cash >= sum([vari_costs[n] * Q[t][n][s] for n in range(N)]) + overhead_cost[t]) # cash constaints else: m.addConstr( C[t - 1][s] >= sum([vari_costs[n] * Q[t][n][s] for n in range(N)]) + overhead_cost[t]) # cash constaints # non-negativity of I_t for s in range(M): for n in range(N): for t in range(T): m.addConstr(I[t][n][s] >= 0) # non-anticipativity # s1 与 s 的顺序没啥影响 # no need for I, R, C for t in range(T): for n in range(N): for s in range(M): m.addConstr(sum([scenarioLink[t][s1][s] * scenario_probs[s1] * Q[t][n][s1] for s1 in range(M)]) == \ Q[t][n][s] * sum([scenarioLink[t][s1][s] * scenario_probs[s1] for s1 in range(M)])) m.addConstr(sum([scenarioLink[t][s1][s] * scenario_probs[s1] * I[t][n][s1] for s1 in range(M)]) == \ I[t][n][s] * sum([scenarioLink[t][s1][s] * scenario_probs[s1] for s1 in range(M)])) m.addConstr( sum([scenarioLink[t][s1][s] * scenario_probs[s1] * delta[t][n][s1] for s1 in range(M)]) == \ delta[t][n][s] * sum([scenarioLink[t][s1][s] * scenario_probs[s1] for s1 in range(M)])) # first-stage decision for s in range(M - 1): for n in range(N): m.addConstr(Q[0][n][s] == Q[0][n][s + 1]) # solve m.update() m.optimize() print('') # output in txt files Qv = [[[0 for s in range(M)] for n in range(N)] for t in range(T) ] # ordering quantity in each period for each product Iv = [[[0 for s in range(M)] for n in range(N)] for t in range(T) ] # end-of-period inventory in each period for each product deltav = [[[0 for s in range(M)] for n in range(N)] for t in range(T)] # whether lost-sale not occurs gv = [[[0 for s in range(M)] for n in range(N)] for t in range(T) ] # order-loan quantity in each period for each product with open('results.txt', 'w') as f: f.write('*********************************\n') f.write('ordering quantity Q in each scenario:\n') for s in range(M): f.write('S%d:\n' % s) for n in range(N): f.write('item %d: ' % n) for t in range(T): f.write('%.1f ' % Q[t][n][s].X) Qv[t][n][s] = Q[t][n][s].X f.write('\n') f.write('\n') f.write( '***************************************************************************************************************\n' ) f.write('end-of-period inventory I in each scenario:\n') for s in range(M): f.write('S%d:\n' % s) for n in range(N): f.write('item %d: ' % n) for t in range(T): f.write('%.1f ' % I[t][n][s].X) Iv[t][n][s] = I[t][n][s].X f.write('\n') f.write('\n') f.write( '***************************************************************\n' ) f.write('not lost-sale delta in each scenario:\n') for s in range(M): f.write('S%d:\n' % s) for n in range(N): f.write('item %d: ' % n) for t in range(T): f.write('%.1f ' % delta[t][n][s].X) deltav[t][n][s] = delta[t][n][s].X f.write('\n') f.write('\n') f.write('*********************************\n') f.write('revenue R in each scenario:\n') for s in range(M): f.write('S%d:\n' % s) for n in range(N): f.write('item %d: ' % n) for t in range(T): f.write('%.1f ' % R[t][n][s].getValue()) f.write('\n') f.write('\n') f.write('*********************************\n') f.write('discounted cash in each scenario:\n') for s in range(M): f.write('S%d: ' % s) f.write('%.1f ' % discounted_cash[s].getValue()) f.write('\n') f.write('*********************************\n') f.write('end-of-period cash C in each scenario:\n') for s in range(M): f.write('S%d:\n' % s) for t in range(T): f.write('%.1f ' % C[t][s].getValue()) f.write(' %.3f:\n' % scenario_probs[s]) f.write('\n') f.write('*********************************\n') f.write('expectd Revenue in each period:\n') for t in range(T): f.write('%.1f ' % expect_revenue_total[t].getValue()) f.write('\n') f.write('varicosts in each period:\n') for t in range(T): f.write('%.1f ' % expect_vari_costs_total[t].getValue()) f.write('\n') f.write('expected end-of-period cash in each period:\n') f.write('%.1f ' % ini_cash) expect_cash = [LinExpr() for t in range(T)] for t in range(T): expect_cash[t] = sum( [C[t][s] * scenario_probs[s] for s in range(M)]) f.write('%.1f ' % expect_cash[t].getValue()) f.write('\n') f.write('final expected discounted cash is: %g\n' % expect_discounted_cash.getValue()) f.write('final expected cash is: %g' % final_cash.getValue()) print('final expected value is: %g' % m.objVal) return m.objVal except GurobiError as e: print('Error code ' + str(e.errno) + ": " + str(e)) except AttributeError: print('Encountered an attribute error')
print "Loading the baseline..." latitude, longitude, baseline_array = product.get_bayes_array(os.path.join(outdir, variety + "-product.nc4")) print "Creating final result..." medians = np.zeros((len(latitude), len(longitude))) confs = np.zeros((len(latitude), len(longitude))) for rr in range(len(latitude)): print rr for cc in range(len(longitude)): values = [] for bayeskey in bayes_arrays: array = bayes_arrays[bayeskey] for gaezkey in gaez_grids: grid = gaez_grids[gaezkey] values.append(product.product(latitude, longitude, array, grid, rr, cc)) values = np.array(values) - baseline_array[rr, cc] if np.all(map(np.isnan, values)): #print "All NaN" medians[rr, cc] = np.nan confs[rr, cc] = np.nan else: median = np.median(values) medians[rr, cc] = median if median > 0: confs[rr, cc] = (2 * sum((values < median) & (values > 0)) + sum(values == median)) / float(len(values)) elif median < 0: confs[rr, cc] = (2 * sum((values > median) & (values < 0)) + sum(values == median)) / float(len(values)) elif median == 0: confs[rr, cc] = sum(values == median) / float(len(values))
# using inheritance importing product import product # and checkoutregister classes import checkoutregister # adding some products into the supermarket product.product("123", "Milk", "2 Litres", "2.0") product.product("789", "Fruits", "2 kgs", "4.0") product.product("456", "Bread", "", "3.5") # greeting message generated for the user print("-----Welcome to FedUni checkout! -----") while True: # using the checkoutregister class from checkoutregister file check_pro_list_items = checkoutregister.checkoutregister() # while condition is true run the code while True: main_class_list = product.product.list_products print() # prompt to get the entry of the product from the user product_code_data = input("Please enter the barcode of your item: ") # add the entered data and scan the product if it is available or not check_pro_list_items.scan_items(product_code_data) print() # prompt to get the entry from the user to continue or not user_loop = input("Would you like to scan another product? (Y/N) ").upper()
ALGO returns all the data, the three dictionaries then here in routes, we look at the ID for the store requested, and return data for the store opposite 3->5 5->8 8->3 then we look at this data and convert to JSON - change numbers for locations to names - change numbers for products to names - add in increase/decrease/staff based on data provided (which array we select from or if staff 1/2/0) (best_prod_per_loc_per_week) (worst_prod_per_loc_per_week) (staff_count_per_loc) """ location_map = {3: "Astoria", 5: "Lower Manhattan", 8: "Hell's Kitchen"} product_file_name = "archive/product.csv" prod_obj = product(product_file_name) @app.route('/shop/{id}/insight/current') def current_insight(): ret = algo.weekoverweek() # return json objects for week 3-4 diffs # look at store 5 looking at data for store 3 best_prod = ret[0][3][2] worst_prod = ret[1][3][2] staff_count = ret[2][3][2] # get name of best product # get name for worst product # get increase or decrease staff staff_item = None