Difference between revisions of "User:Muhammad.ihsan13"

From ccitonlinewiki
Jump to: navigation, search
(Final Report Hydrogen Storage Optimization)
(Final Report Hydrogen Storage Optimization)
Line 31: Line 31:
 
'''''
 
'''''
 
Dengan optimasi hidrogen yang memiliki kapasitas maksimal 1 liter dan biaya maksimal produksi sebesar Rp. 500.000, maka pemrograman untuk menghitung ukuran tabung yang optimal :
 
Dengan optimasi hidrogen yang memiliki kapasitas maksimal 1 liter dan biaya maksimal produksi sebesar Rp. 500.000, maka pemrograman untuk menghitung ukuran tabung yang optimal :
 
 
import numpy as np
 
import numpy as np
 
from scipy.optimize import minimize
 
from scipy.optimize import minimize
 +
 
def calculateSurfaceArea(radius, height):
 
def calculateSurfaceArea(radius, height):
 
     return 2 * np.pi * radius * height + 2 * np.pi * radius**2
 
     return 2 * np.pi * radius * height + 2 * np.pi * radius**2
 +
 
def calculateVolume(radius, height):
 
def calculateVolume(radius, height):
 
     return np.pi * radius**2 * height
 
     return np.pi * radius**2 * height
 +
 
# Set constant variables
 
# Set constant variables
 
target_volume = 1000  # Constant volume (in cubic centimeters)
 
target_volume = 1000  # Constant volume (in cubic centimeters)
 +
 
# Define the objective function to minimize
 
# Define the objective function to minimize
 
def objectiveFunction(x):
 
def objectiveFunction(x):
Line 45: Line 48:
 
     surface_area = calculateSurfaceArea(radius, height)
 
     surface_area = calculateSurfaceArea(radius, height)
 
     return surface_area
 
     return surface_area
 +
 
# Define the constraint function
 
# Define the constraint function
 
def constraintFunction(x):
 
def constraintFunction(x):
Line 50: Line 54:
 
     volume = calculateVolume(radius, height)
 
     volume = calculateVolume(radius, height)
 
     return volume - target_volume
 
     return volume - target_volume
 +
 
# Set initial guess for optimization variables
 
# Set initial guess for optimization variables
 
initial_guess = [1.0, 1.0]
 
initial_guess = [1.0, 1.0]
 +
 
# Define the bounds for the variables
 
# Define the bounds for the variables
 
bounds = [(0, None), (0, None)]
 
bounds = [(0, None), (0, None)]
 +
 
# Define the optimization problem
 
# Define the optimization problem
 
constraint = {'type': 'eq', 'fun': constraintFunction}
 
constraint = {'type': 'eq', 'fun': constraintFunction}
 +
 
# Solve the optimization problem
 
# Solve the optimization problem
 
result = minimize(objectiveFunction, initial_guess, method='SLSQP', bounds=bounds, constraints=constraint)
 
result = minimize(objectiveFunction, initial_guess, method='SLSQP', bounds=bounds, constraints=constraint)
 +
 
# Extract the optimized variables
 
# Extract the optimized variables
 
optimal_radius, optimal_height = result.x
 
optimal_radius, optimal_height = result.x
 +
 
# Calculate the optimized surface area
 
# Calculate the optimized surface area
 
optimal_surface_area = calculateSurfaceArea(optimal_radius, optimal_height)
 
optimal_surface_area = calculateSurfaceArea(optimal_radius, optimal_height)
 +
 
# Display the results
 
# Display the results
 
print('Optimal Radius:', optimal_radius, 'cm')
 
print('Optimal Radius:', optimal_radius, 'cm')
 
print('Optimal Height:', optimal_height, 'cm')
 
print('Optimal Height:', optimal_height, 'cm')
 
print('Optimal Surface Area:', optimal_surface_area, 'cm^2')
 
print('Optimal Surface Area:', optimal_surface_area, 'cm^2')
Sehingga mendapatkan hasil
 
Optimal Radius: 5.419262767614773 cm
 
Optimal Height: 10.83851313481415 cm
 
Optimal Surface Area: 553.5810444881138 cm^2
 

Revision as of 17:58, 12 June 2023

Hydrogen Storage Optimization

In this study case i will use a commonly used numerical method called "particle swarm optimization" (PSO):

1. Define the Problem: Clearly state the objective function that represents the performance criteria of the hydrogen storage system. It could be maximizing the storage capacity, minimizing the weight or volume, or optimizing any other relevant parameter.

2. Define Variables and Constraints: Identify the variables that can be adjusted to optimize the system, such as tank dimensions, materials, operating conditions, etc. Also, define any constraints that need to be satisfied, such as pressure limits, safety requirements, or cost considerations.

3. Initialize the Swarm: Create a population of potential solutions (particles) that represent different configurations of the hydrogen storage system. Randomly initialize their positions and velocities within the search space.

4. Evaluate Fitness: Evaluate the fitness of each particle by applying the objective function to its corresponding configuration. This step involves performing calculations and simulations to determine the system's performance for each particle.

5. Update Particle's Best Position: For each particle, compare its fitness with the best fitness achieved by that particle so far. If the current fitness is better, update the particle's best position accordingly.

6. Update Global Best Position: Identify the particle with the best fitness among all the particles and record its position as the global best position found so far.

7. Update Velocities and Positions: Update the velocities and positions of each particle based on its own best position and the global best position. This step involves using mathematical equations that incorporate inertia, cognitive, and social parameters to guide the particles' movement.

8. Repeat: Repeat steps 4 to 7 until a termination criterion is met. This criterion could be a maximum number of iterations, reaching a desired fitness threshold, or other convergence criteria.

9. Extract Optimal Solution: Once the algorithm terminates, the particle with the best fitness (global best) represents the optimized design and configuration of the hydrogen storage system. Extract the corresponding parameters and evaluate their values.

10. Validate and Refine: Validate the optimal solution obtained by implementing it in practical applications or conducting further simulations. Refine the solution if necessary based on additional constraints or considerations.

Particle swarm optimization is just one of many numerical methods available for optimization problems. Depending on the specific characteristics of the hydrogen storage system and the optimization goals, other methods like genetic algorithms, simulated annealing, or gradient-based optimization techniques may also be applicable.


Final Report Hydrogen Storage Optimization

Dengan optimasi hidrogen yang memiliki kapasitas maksimal 1 liter dan biaya maksimal produksi sebesar Rp. 500.000, maka pemrograman untuk menghitung ukuran tabung yang optimal : import numpy as np from scipy.optimize import minimize

def calculateSurfaceArea(radius, height):

   return 2 * np.pi * radius * height + 2 * np.pi * radius**2

def calculateVolume(radius, height):

   return np.pi * radius**2 * height
  1. Set constant variables

target_volume = 1000 # Constant volume (in cubic centimeters)

  1. Define the objective function to minimize

def objectiveFunction(x):

   radius, height = x
   surface_area = calculateSurfaceArea(radius, height)
   return surface_area
  1. Define the constraint function

def constraintFunction(x):

   radius, height = x
   volume = calculateVolume(radius, height)
   return volume - target_volume
  1. Set initial guess for optimization variables

initial_guess = [1.0, 1.0]

  1. Define the bounds for the variables

bounds = [(0, None), (0, None)]

  1. Define the optimization problem

constraint = {'type': 'eq', 'fun': constraintFunction}

  1. Solve the optimization problem

result = minimize(objectiveFunction, initial_guess, method='SLSQP', bounds=bounds, constraints=constraint)

  1. Extract the optimized variables

optimal_radius, optimal_height = result.x

  1. Calculate the optimized surface area

optimal_surface_area = calculateSurfaceArea(optimal_radius, optimal_height)

  1. Display the results

print('Optimal Radius:', optimal_radius, 'cm') print('Optimal Height:', optimal_height, 'cm') print('Optimal Surface Area:', optimal_surface_area, 'cm^2')