Created
September 3, 2016 17:57
-
-
Save amitjamadagni/3c4fe9358df92e0c54fa78f68a55b3dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Line # Mem usage Increment Line Contents | |
================================================ | |
320 37.2 MiB 0.0 MiB @profile | |
321 def func(): | |
322 37.2 MiB 0.0 MiB n_products = input("Enter the number of products (that is add +1 to the actual number) : ") | |
323 37.2 MiB 0.0 MiB time_steps = input("Enter the number of time steps (should be equal to the above number of products) : ") | |
324 37.2 MiB 0.0 MiB demand_mat = input("Enter the demand matrix with time instance as columns and products as rows : ") | |
325 37.2 MiB 0.0 MiB max_price = input("Enter the maximum price for each product as an array : ") | |
326 37.2 MiB 0.0 MiB min_price = input("Enter the minimum price for each product as an array : ") | |
327 37.2 MiB 0.0 MiB print "Creating the pricing object " | |
328 | |
329 37.2 MiB 0.0 MiB pricing_obj = Pricing(time_steps, n_products, demand_mat, max_price, min_price) | |
330 | |
331 37.2 MiB 0.0 MiB print "Generating the independent vectors once for all the cases to follow" | |
332 37.2 MiB 0.0 MiB pv = pricing_obj.independent_price_vectors() | |
333 | |
334 # generating the respective beta matrix | |
335 37.2 MiB 0.0 MiB distribution = raw_input("Enter the distribution, the supported distributions are :\n1. Normal (N) \n2. Poisson (P)\n ") | |
336 37.2 MiB 0.0 MiB print "Generating the beta matrix for the above independent vectors using the above distribution :",distribution | |
337 37.2 MiB 0.0 MiB if distribution == "N": | |
338 37.2 MiB 0.0 MiB print "Choosen distribution is Normal" | |
339 37.4 MiB 0.2 MiB beta_matrix = pricing_obj.beta_mat_normal(pv) | |
340 elif distribution == "P": | |
341 print "Choosen distribution is Poisson" | |
342 beta_matrix = pricing_obj.beta_mat_poisson(pv) | |
343 else: | |
344 print "Error : choose N for Normal, P for Poisson" | |
345 | |
346 37.4 MiB 0.0 MiB bound_tuple = tuple((pricing_obj._pl[i], pricing_obj._ph[i]) for i in range(len(pricing_obj._ph))) | |
347 | |
348 37.4 MiB 0.0 MiB initial_guess = input("Enter an initial guess for the optimal solution generation : ") | |
349 | |
350 # generating different optimal solutions depending on various conditions | |
351 # TODO : this is to be automated to generate the final solution, as the bounds are unknown this | |
352 # that is a partial blocker or may be a full blocker. | |
353 # y = optimal_solution(x, optimal_function, optimal_func_der, optimal_func_hess, [23, 15.5, 36.4, 22.3], beta_matrix, bound_tuple) | |
354 37.4 MiB 0.0 MiB print "Generating the optimal solution to be compared with the bound in order to predict the pricing at future times ..." | |
355 37.4 MiB 0.0 MiB warnings.filterwarnings("ignore") | |
356 37.4 MiB 0.0 MiB if distribution == "N": | |
357 37.4 MiB 0.0 MiB optimal_set = [] | |
358 37.4 MiB 0.0 MiB t_end = time.time() + 60 * 1 | |
359 38.2 MiB 0.8 MiB while time.time() < t_end: | |
360 38.2 MiB 0.0 MiB y = optimal_solution_normal(pricing_obj, optimal_function_normal, optimal_func_der_normal, optimal_func_hess_normal, initial_guess, beta_matrix, bound_tuple) | |
361 38.2 MiB 0.0 MiB optimal_set.append(y) | |
362 38.2 MiB 0.0 MiB least = np.argsort([opt[0] for opt in optimal_set]) | |
363 38.2 MiB 0.0 MiB opt = [] | |
364 38.2 MiB 0.0 MiB for ind in least: | |
365 38.2 MiB 0.0 MiB opt.append(optimal_set[ind]) | |
366 38.2 MiB 0.0 MiB for i in range(len(opt)): | |
367 38.2 MiB 0.0 MiB if np.array_equal(opt[i], np.array(initial_guess)): | |
368 continue | |
369 else: | |
370 38.2 MiB 0.0 MiB print " optimal solution for normal distribution: ", opt[i] | |
371 38.2 MiB 0.0 MiB break | |
372 else: | |
373 print " optimal solution for normal distribution: ", opt[0] | |
374 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment