### Implement Optimization Strategy (Python) Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Provides a template for the `get_my_solution` function, where users can implement their optimization strategies. It takes `actual_demand` as input and returns a `solution` in the specified format. The example logic demonstrates buying servers at time step 1 and holding them in subsequent steps. ```python import numpy as np import pandas as pd from evaluation import get_actual_demand from utils import save_solution, load_problem_data from seeds import known_seeds def get_my_solution(actual_demand): """ Implement your optimization strategy here. Parameters: ----------- actual_demand : pandas DataFrame Demand data with columns ['time_step', 'server_generation', 'high', 'medium', 'low'] Returns: -------- solution : list of dicts or pandas DataFrame Solution with columns ['time_step', 'datacenter_id', 'server_generation', 'server_id', 'action'] """ solution = [] # Example: Buy servers at time step 1 to meet demand for idx, row in actual_demand[actual_demand['time_step'] == 1].iterrows(): server_gen = row['server_generation'] total_demand = row['high'] + row['medium'] + row['low'] # Buy servers to meet demand (simplified logic) num_servers = max(1, int(total_demand / 100)) for i in range(num_servers): solution.append({ 'time_step': 1, 'datacenter_id': 'DC1', 'server_generation': server_gen, 'server_id': f'{server_gen}_srv_{i}', 'action': 'buy' }) # Hold all servers in subsequent time steps for ts in range(2, 169): for srv in solution: if srv['time_step'] == 1: solution.append({ 'time_step': ts, 'datacenter_id': srv['datacenter_id'], 'server_generation': srv['server_generation'], 'server_id': srv['server_id'], 'action': 'hold' }) return solution # Usage example demand, datacenters, servers, selling_prices = load_problem_data() seeds = known_seeds('training') for seed in seeds: np.random.seed(seed) actual_demand = get_actual_demand(demand) solution = get_my_solution(actual_demand) save_solution(solution, f'./output/{seed}.json') print(f"Saved solution for seed {seed}") ``` -------------------------------- ### Get Configuration Values (Python) Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Retrieves various configuration constants using the `get_known` function. This allows accessing predefined lists for datacenters, actions, server generations, latency sensitivities, required solution columns, and the total number of time steps in the problem. ```python from evaluation import get_known # Get available datacenter IDs datacenters = get_known('datacenter_id') # Returns: ['DC1', 'DC2', 'DC3', 'DC4'] # Get available actions actions = get_known('actions') # Returns: ['buy', 'hold', 'move', 'dismiss'] # Get server generations server_generations = get_known('server_generation') # Returns: ['CPU.S1', 'CPU.S2', 'CPU.S3', 'CPU.S4', 'GPU.S1', 'GPU.S2', 'GPU.S3'] # Get latency sensitivities latencies = get_known('latency_sensitivity') # Returns: ['high', 'medium', 'low'] # Get required solution columns required_cols = get_known('required_columns') # Returns: ['time_step', 'datacenter_id', 'server_generation', 'server_id', 'action'] # Get number of time steps time_steps = get_known('time_steps') ``` -------------------------------- ### Get Actual Demand Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Generates stochastic demand patterns by applying random walk perturbations to base demand data. This function is crucial for simulating realistic and varied customer demand over time. ```APIDOC ## Get Actual Demand ### Description Generates stochastic demand patterns for server generations and latency sensitivities. ### Method POST (simulated) ### Endpoint /demand/generate ### Parameters #### Path Parameters None #### Query Parameters * **seed** (integer) - Optional - Random seed for reproducible demand generation. #### Request Body * **demand_data** (DataFrame) - Required - DataFrame containing base demand patterns, typically loaded from a CSV. ### Request Example ```json { "demand_data": { "time_step": [1, 1, 1, 2, 2, 2], "server_generation": ["CPU.S1", "CPU.S2", "GPU.S1", "CPU.S1", "CPU.S2", "GPU.S1"], "high": [150, 180, 90, 155, 185, 92], "medium": [200, 220, 110, 205, 225, 112], "low": [100, 120, 50, 98, 118, 48] } } ``` ### Response #### Success Response (200) - **actual_demand** (DataFrame) - DataFrame with columns `['time_step', 'server_generation', 'high', 'medium', 'low']` representing the generated stochastic demand. #### Response Example ```json { "actual_demand": [ {"time_step": 1, "server_generation": "CPU.S1", "high": 150, "medium": 200, "low": 100}, {"time_step": 1, "server_generation": "CPU.S2", "high": 180, "medium": 220, "low": 120}, {"time_step": 1, "server_generation": "GPU.S1", "high": 90, "medium": 110, "low": 50}, {"time_step": 2, "server_generation": "CPU.S1", "high": 155, "medium": 205, "low": 98} ] } ``` ``` -------------------------------- ### Check Datacenter Slots Constraint with Python Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt This Python code validates datacenter capacity constraints using the `check_datacenter_slots_size_constraint` function. It takes a pandas DataFrame representing server deployments and their datacenter assignments. The function raises a ValueError if any datacenter exceeds its capacity. Example usage includes both a satisfied and a violated constraint scenario. ```python import pandas as pd from evaluation import check_datacenter_slots_size_constraint # Example fleet DataFrame with server deployments fleet = pd.DataFrame({ 'server_id': ['srv_001', 'srv_002', 'srv_003'], 'datacenter_id': ['DC1', 'DC1', 'DC2'], 'slots_size': [2, 3, 2], 'slots_capacity': [10, 10, 5] }) # Check constraint (raises ValueError if violated) try: check_datacenter_slots_size_constraint(fleet) print("Constraint satisfied: All datacenters within capacity") except ValueError as e: print(f"Constraint violated: {e}") # Output: "Constraint 2 has been violated." # Example with violation fleet_violation = pd.DataFrame({ 'server_id': ['srv_001', 'srv_002', 'srv_003', 'srv_004'], 'datacenter_id': ['DC2', 'DC2', 'DC2', 'DC2'], 'slots_size': [2, 2, 2, 2], 'slots_capacity': [5, 5, 5, 5] }) check_datacenter_slots_size_constraint(fleet_violation) # Raises: ValueError('Constraint 2 has been violated.') ``` -------------------------------- ### Create, Save, and Load Solution Data (Python) Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Demonstrates how to create a solution as a list of dictionaries, save it to a JSON file, and then load it back. This is useful for persisting and retrieving optimization results. It assumes the existence of `save_solution` and `load_solution` functions. ```python solution = [ {'time_step': 1, 'datacenter_id': 'DC1', 'server_generation': 'CPU.S1', 'server_id': 'srv_001', 'action': 'buy'}, {'time_step': 1, 'datacenter_id': 'DC2', 'server_generation': 'GPU.S1', 'server_id': 'srv_002', 'action': 'buy'}, {'time_step': 2, 'datacenter_id': 'DC1', 'server_generation': 'CPU.S1', 'server_id': 'srv_001', 'action': 'hold'}, {'time_step': 2, 'datacenter_id': 'DC3', 'server_generation': 'GPU.S1', 'server_id': 'srv_002', 'action': 'move'}, {'time_step': 3, 'datacenter_id': 'DC1', 'server_generation': 'CPU.S1', 'server_id': 'srv_001', 'action': 'dismiss'} ] # Save solution to JSON save_solution(solution, './output/my_solution.json') # Load solution from JSON loaded_solution = load_solution('./output/my_solution.json') # Returns: pandas DataFrame with required columns print(loaded_solution.head()) ``` -------------------------------- ### Evaluate Datacenter Solution Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Main entry point for evaluating a solution against problem constraints and objectives. It takes detailed problem data and a proposed solution, returning an objective score based on utilization, lifespan, and profit across time steps. Requires numpy, pandas, and custom evaluation/utility modules. ```python import numpy as np import pandas as pd from evaluation import evaluation_function from utils import load_problem_data, load_solution # Load problem data demand, datacenters, servers, selling_prices = load_problem_data('./data/') # Load or create a solution solution = load_solution('./data/solution_example.json') # Evaluate solution with specific seed seed = 1741 objective_score = evaluation_function( solution=solution, demand=demand, datacenters=datacenters, servers=servers, selling_prices=selling_prices, time_steps=168, seed=seed, verbose=1 ) # Output: prints time-step by time-step metrics # {'time-step': 1, 'O': 1234.56, 'U': 0.85, 'L': 0.92, 'P': 15000.0} # {'time-step': 2, 'O': 2500.12, 'U': 0.87, 'L': 0.93, 'P': 14500.0} # ... # Returns: Total objective value across all time steps (float) or None if constraints violated print(f"Final Objective Score: {objective_score}") ``` -------------------------------- ### Generate Actual Demand Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Generates stochastic demand patterns for server generations and latency sensitivities using a random walk perturbation on base demand data. Requires numpy and pandas for data manipulation. Returns a DataFrame detailing demand per time step, server generation, and latency. ```python import numpy as np import pandas as pd from evaluation import get_actual_demand # Load base demand data demand = pd.read_csv('./data/demand.csv') # Set random seed for reproducibility np.random.seed(1741) # Generate actual demand with random walk perturbations actual_demand = get_actual_demand(demand) # Returns: DataFrame with columns ['time_step', 'server_generation', 'high', 'medium', 'low'] # Example output: # time_step server_generation high medium low # 1 CPU.S1 150 200 100 # 1 CPU.S2 180 220 120 # 1 GPU.S1 90 110 50 # 2 CPU.S1 155 205 98 # ... # Access specific time-step demand ts_demand = actual_demand[actual_demand['time_step'] == 1] print(ts_demand) ``` -------------------------------- ### Validate Solution Format with Pandas Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt This snippet demonstrates how to validate the format of a solution DataFrame using pandas. It checks for the presence of required columns and ensures that action values are within the allowed set. Dependencies include pandas and a get_known function. ```python import pandas as pd # Assuming 'solution' is a list of dictionaries or similar structure solution_df = pd.DataFrame(solution) assert all(col in solution_df.columns for col in get_known('required_columns')), "Missing required columns" assert solution_df['action'].isin(get_known('actions')).all(), "Invalid action found" ``` -------------------------------- ### Save and Load Solutions Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Utility functions for persisting and retrieving optimization solutions. Solutions can be saved to and loaded from JSON files, facilitating the management of different strategy attempts. ```python import pandas as pd from utils import save_solution, load_solution # Note: The actual implementation for saving and loading solutions is not provided in the snippet. ``` -------------------------------- ### Load Problem Data Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Loads all necessary configuration and data files required to define a specific datacenter fleet management problem instance. This includes demand patterns, datacenter specifications, server details, and selling prices. ```APIDOC ## Load Problem Data ### Description Loads all required problem data from CSV files into pandas DataFrames. ### Method GET ### Endpoint /data/problem ### Parameters #### Path Parameters None #### Query Parameters * **data_directory** (string) - Optional - The path to the directory containing the data CSV files. Defaults to './data/'. ### Request Example GET /data/problem?data_directory=./custom_path/ ### Response #### Success Response (200) - **demand** (DataFrame) - DataFrame with columns `['time_step', 'latency_sensitivity', 'CPU.S1', 'CPU.S2', ...]`. - **datacenters** (DataFrame) - DataFrame with columns `['datacenter_id', 'slots_capacity', 'cost_of_energy', 'latency_sensitivity', 'cost_of_moving']`. - **servers** (DataFrame) - DataFrame with columns `['server_generation', 'server_type', 'release_time', 'capacity', 'purchase_price', 'energy_consumption', 'life_expectancy', 'average_maintenance_fee', 'slots_size']`. - **selling_prices** (DataFrame) - DataFrame with columns `['server_generation', 'latency_sensitivity', 'selling_price']`. #### Response Example ```json { "demand": [ {"time_step": 1, "latency_sensitivity": "high", "CPU.S1": 150, "CPU.S2": 180}, {"time_step": 1, "latency_sensitivity": "medium", "CPU.S1": 200, "CPU.S2": 220} ], "datacenters": [ {"datacenter_id": "DC1", "slots_capacity": 1000, "cost_of_energy": 0.1, "latency_sensitivity": "high", "cost_of_moving": 5000} ], "servers": [ {"server_generation": "CPU.S1", "server_type": "CPU", "release_time": 0, "capacity": 10, "purchase_price": 500, "energy_consumption": 100, "life_expectancy": 5, "average_maintenance_fee": 20, "slots_size": 1} ], "selling_prices": [ {"server_generation": "CPU.S1", "latency_sensitivity": "high", "selling_price": 800} ] } ``` ``` -------------------------------- ### Load Problem Data Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Loads all necessary problem data from CSV files, including demand, datacenter specifications, server details, and selling prices. Can load from a default directory or a custom path. Returns multiple pandas DataFrames. ```python from utils import load_problem_data # Load all problem data from default directory demand, datacenters, servers, selling_prices = load_problem_data() # Or specify custom data directory demand, datacenters, servers, selling_prices = load_problem_data('./custom_path/') # demand: DataFrame with columns ['time_step', 'latency_sensitivity', 'CPU.S1', 'CPU.S2', ...] # datacenters: DataFrame with columns ['datacenter_id', 'slots_capacity', 'cost_of_energy', 'latency_sensitivity', 'cost_of_moving'] # servers: DataFrame with columns ['server_generation', 'server_type', 'release_time', 'capacity', 'purchase_price', 'energy_consumption', 'life_expectancy', 'average_maintenance_fee', 'slots_size'] # selling_prices: DataFrame with columns ['server_generation', 'latency_sensitivity', 'selling_price'] print(f"Datacenters available: {datacenters['datacenter_id'].unique()}") # Output: ['DC1', 'DC2', 'DC3', 'DC4'] print(f"Server generations: {servers['server_generation'].unique()}") # Output: ['CPU.S1', 'CPU.S2', 'CPU.S3', 'CPU.S4', 'GPU.S1', 'GPU.S2', 'GPU.S3'] ``` -------------------------------- ### Save and Load Solutions Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Utility functions for persisting and retrieving optimization solutions. Solutions can be saved to a JSON file and loaded back into the system, allowing for the management and reuse of developed strategies. ```APIDOC ## Save and Load Solutions ### Description Utilities for persisting solutions in JSON format. ### Method GET/POST (for loading/saving) ### Endpoint /solutions/{solution_id} ### Parameters #### Path Parameters * **solution_id** (string) - The unique identifier for the solution. #### Query Parameters * **file_path** (string) - The path to the JSON file for saving or loading. #### Request Body (for Save) * **solution_data** (object) - Required - The solution object to be saved. ### Request Example (Save) POST /solutions/my_solution_1?file_path=./solutions/my_solution_1.json ```json { "solution_data": { "purchases": [...], "moves": [...], "holds": [...], "dismissals": [...] } } ``` ### Request Example (Load) GET /solutions/my_solution_1?file_path=./solutions/my_solution_1.json ### Response #### Success Response (200 - Load) - **loaded_solution** (object) - The solution object loaded from the JSON file. #### Success Response (201 - Save) - **message** (string) - Confirmation that the solution was saved successfully. #### Response Example (Load) ```json { "loaded_solution": { "purchases": [...], "moves": [...], "holds": [...], "dismissals": [...] } } ``` #### Response Example (Save) ```json { "message": "Solution my_solution_1 saved successfully to ./solutions/my_solution_1.json" } ``` ``` -------------------------------- ### Retrieve Known Seeds for Simulation (Python) Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt Fetches predefined random seeds used for training and testing simulations. It utilizes the `known_seeds` function from the `seeds` module. The output is a list of integers that can be used to set the random seed for reproducible results. ```python from seeds import known_seeds import numpy as np from evaluation import get_actual_demand # Get training seeds training_seeds = known_seeds('training') print(training_seeds) # Get test seeds test_seeds = known_seeds('test') print(test_seeds) # Use seeds for evaluation loop for seed in training_seeds: np.random.seed(seed) actual_demand = get_actual_demand(demand) # Assuming 'demand' is loaded elsewhere solution = get_my_solution(actual_demand) # Assuming 'get_my_solution' is defined score = evaluation_function(solution, demand, datacenters, servers, selling_prices, seed=seed) # Assuming other variables and functions are defined print(f"Seed {seed}: Score = {score}") ``` -------------------------------- ### Evaluation Function Source: https://context7.com/lax999/tech_arena_24_phase_1/llms.txt The main entry point for evaluating a proposed solution against the defined problem constraints and optimization objectives. It simulates the datacenter operations over a specified number of time steps and returns an overall objective score. ```APIDOC ## Evaluation Function ### Description Main entry point for evaluating a solution against problem constraints and objectives. ### Method POST (simulated) ### Endpoint / ### Parameters #### Path Parameters None #### Query Parameters * **seed** (integer) - Optional - Random seed for stochastic demand and server failure generation. * **verbose** (integer) - Optional - Controls the level of logging during evaluation (e.g., 1 for step-by-step metrics). #### Request Body * **solution** (object) - Required - The proposed solution to evaluate, including server purchases, movements, holds, and dismissals. * **demand** (DataFrame) - Required - DataFrame containing base demand patterns. * **datacenters** (DataFrame) - Required - DataFrame describing the datacenters. * **servers** (DataFrame) - Required - DataFrame describing the available server types and their properties. * **selling_prices** (DataFrame) - Required - DataFrame containing selling prices for server generations across different latency sensitivities. * **time_steps** (integer) - Required - The total number of time steps to simulate. ### Request Example ```json { "solution": { ... }, "demand": { ... }, "datacenters": { ... }, "servers": { ... }, "selling_prices": { ... }, "time_steps": 168 } ``` ### Response #### Success Response (200) - **objective_score** (float) - The total objective score across all time steps. - **metrics** (list of objects) - Detailed metrics for each time step (if verbose is enabled). #### Response Example ```json { "objective_score": 15000.75, "metrics": [ {"time_step": 1, "O": 1234.56, "U": 0.85, "L": 0.92, "P": 15000.0}, {"time_step": 2, "O": 2500.12, "U": 0.87, "L": 0.93, "P": 14500.0} ] } ``` #### Error Response (400) - **error** (string) - Description of the constraint violation or error encountered during evaluation. #### Error Example ```json { "error": "Constraint violated: Datacenter DC1 exceeds capacity." } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.