Pragya Jatav commited on
Commit
4213369
·
1 Parent(s): 2d928fb
Files changed (1) hide show
  1. classes.py +35 -35
classes.py CHANGED
@@ -3,7 +3,7 @@ from scipy.optimize import minimize, LinearConstraint, NonlinearConstraint
3
  from collections import OrderedDict
4
  import pandas as pd
5
  from numerize.numerize import numerize
6
- from gekko import GEKKO
7
 
8
  def class_to_dict(class_instance):
9
  attr_dict = {}
@@ -447,51 +447,51 @@ class Scenario:
447
  return (param_dicts["y_max"][channel] - param_dicts["y_min"][channel])*(x_out + param_dicts["y_min"][channel])*104
448
 
449
 
450
- def spends_optimisation(self, spends_percent,channels_list):
451
- m = GEKKO(remote=False)
452
- # Define variables
453
- # Initialize 13 variables with specific bounds
454
- response_curve_params = pd.read_excel(r"C:\Users\PragyaJatav\Downloads\Untitled Folder 2\simulator uploaded - Copy\Simulator-UOPX\response_curves_parameters.xlsx",index_col = "channel")
455
- param_dicts = {col: response_curve_params[col].to_dict() for col in response_curve_params.columns}
456
 
457
- initial_values = list(param_dicts["x_min"].values())
458
- current_spends = list(param_dicts["current_spends"].values())
459
- lower_bounds = list(param_dicts["x_min"].values())
460
 
461
- num_channels = len(channels_list)
462
 
463
- x_vars=[]
464
- x_vars = [m.Var(value=param_dicts["current_spends"][_], lb=param_dicts["x_min"][_]*104, ub=5*param_dicts["current_spends"][_]) for _ in channels_list]
465
- print(x_vars)
466
- # x_vars,lower_bounds
467
 
468
- # Define the objective function to minimize
469
- cost = 0
470
- spends = 0
471
- i = 0
472
- for i,c in enumerate(channels_list):
473
- # print(c)
474
- # print(x_vars[i])
475
- cost = cost + (self.cost_func(c, x_vars[i]))
476
- spends = spends +x_vars[i]
477
 
478
 
479
- m.Maximize(cost)
480
 
481
- # Define constraints
482
- m.Equation(spends == sum(current_spends)*(1 + spends_percent / 100))
483
- m.Equation(spends <= sum(current_spends)*0.5)
484
- m.Equation(spends >= sum(current_spends)*1.5)
485
 
486
- m.solve(disp=True)
487
 
488
- for i, var in enumerate(x_vars):
489
- print(f"x{i+1} = {var.value[0]}")
490
 
491
- for channel_name, modified_spends in zip(channels_list, x_vars):
492
- self.update(channel_name, modified_spends.value[0])
493
 
494
- return zip(channels_list, x_vars)
495
 
496
  def save(self):
497
  details = {}
 
3
  from collections import OrderedDict
4
  import pandas as pd
5
  from numerize.numerize import numerize
6
+ # from gekko import GEKKO
7
 
8
  def class_to_dict(class_instance):
9
  attr_dict = {}
 
447
  return (param_dicts["y_max"][channel] - param_dicts["y_min"][channel])*(x_out + param_dicts["y_min"][channel])*104
448
 
449
 
450
+ # def spends_optimisation(self, spends_percent,channels_list):
451
+ # m = GEKKO(remote=False)
452
+ # # Define variables
453
+ # # Initialize 13 variables with specific bounds
454
+ # response_curve_params = pd.read_excel(r"C:\Users\PragyaJatav\Downloads\Untitled Folder 2\simulator uploaded - Copy\Simulator-UOPX\response_curves_parameters.xlsx",index_col = "channel")
455
+ # param_dicts = {col: response_curve_params[col].to_dict() for col in response_curve_params.columns}
456
 
457
+ # initial_values = list(param_dicts["x_min"].values())
458
+ # current_spends = list(param_dicts["current_spends"].values())
459
+ # lower_bounds = list(param_dicts["x_min"].values())
460
 
461
+ # num_channels = len(channels_list)
462
 
463
+ # x_vars=[]
464
+ # x_vars = [m.Var(value=param_dicts["current_spends"][_], lb=param_dicts["x_min"][_]*104, ub=5*param_dicts["current_spends"][_]) for _ in channels_list]
465
+ # print(x_vars)
466
+ # # x_vars,lower_bounds
467
 
468
+ # # Define the objective function to minimize
469
+ # cost = 0
470
+ # spends = 0
471
+ # i = 0
472
+ # for i,c in enumerate(channels_list):
473
+ # # print(c)
474
+ # # print(x_vars[i])
475
+ # cost = cost + (self.cost_func(c, x_vars[i]))
476
+ # spends = spends +x_vars[i]
477
 
478
 
479
+ # m.Maximize(cost)
480
 
481
+ # # Define constraints
482
+ # m.Equation(spends == sum(current_spends)*(1 + spends_percent / 100))
483
+ # m.Equation(spends <= sum(current_spends)*0.5)
484
+ # m.Equation(spends >= sum(current_spends)*1.5)
485
 
486
+ # m.solve(disp=True)
487
 
488
+ # for i, var in enumerate(x_vars):
489
+ # print(f"x{i+1} = {var.value[0]}")
490
 
491
+ # for channel_name, modified_spends in zip(channels_list, x_vars):
492
+ # self.update(channel_name, modified_spends.value[0])
493
 
494
+ # return zip(channels_list, x_vars)
495
 
496
  def save(self):
497
  details = {}