function [val,f,g] = objective_model(x)

for i=1:6
    if x(i) < LB(i)
        x(i) = LB(i);
    end
    if x(i) > UB(i)
        x(i) = UB(i);
    end
end

L = x(1); %length (m)
B = x(2); %beam (m)
D = x(3); %depth (m)
T = x(4); %draft (m)
C_B = x(5); %block coefficient
V_k = x(6); %speed (knots)

penalty_coef = 1e1;

%%relashions
handling_rate = 8000; %handling rate
fuel_price = 100; %fuel price 
round_trip_miles = 5000; %round trip miles

KG = 1.0 + 0.52*D; %vert. center of gravity
BMT = ((0.085*C_B - 0.002)*B^2)/(T*C_B); %metacentric radius
KB = 0.53*T; %vert. center of buoyancy
W_s = 0.034*(L^1.7)*(B^0.7)*(D^0.4)*(C_B^0.5); %steel weight
W_o = (L^0.8)*(B^0.6)*(D^0.3)*(C_B^0.1); %outfit weight
displacement = 1.025*L*B*T*C_B; %displacement
V = 0.5114*V_k;
g = 9.8065;
Fn = V/((g*L)^0.5); %Froude number
a = 4977.06*(C_B^2) - 8105.61*(C_B) + 4456.51;
b = -10847.2*(C_B^2) + 12817*C_B - 6960.32;
P = (displacement^(2/3))*(V_k^3)/(a+b*Fn); %Power
W_m = 0.17*(P^0.9); %machinery weight
light_ship_weight = W_s + W_o + W_m; %light shipweight
DWT = displacement - light_ship_weight; %deadweight
running_costs = 40000*(DWT^0.3); %running costs
daily_consumption = 0.19*P*24/1000+0.2; %daily consumption
sea_days = round_trip_miles/(24*V_k); %sea days
port_cost = 6.3*(DWT^0.8); % port cost
fuel_carried = daily_consumption*(sea_days+5); %fuel carried
MDWT = 2.0*(DWT^0.5); %miscellaneous DWT
CDWT = DWT - fuel_carried - MDWT; %cargo deadweight
port_days = 2*((CDWT/handling_rate) + 0.5); % port days
RTPA = 350/(sea_days + port_days); %round trips per year
annual_cargo_capacity = DWT*RTPA; %annual cargo capacity
ship_cost = 1.3*(2000*(W_s^0.85) + 3500*W_o + 2400*(P^0.8)); %ship cost
capital_costs = 0.2*ship_cost; % capital costs 
fuel_cost = 1.05*daily_consumption*sea_days*fuel_price; %fuel cost
voyage_costs = (fuel_cost + port_cost)*RTPA; %voyage costs
annual_cost = capital_costs + running_costs + voyage_costs; %annual cost
unit_transportation_cost = annual_cost/annual_cargo_capacity;

% constraint values that should be <= 0
g(1,1) = 6 - L/B;
g(2,1) = L/D - 15;
g(3,1) = L/T - 19;
g(4,1) = T - 0.45*(DWT^0.31);
g(5,1) = T - 0.7*D - 0.7;
g(6,1) = 25000-DWT;
g(7,1) = DWT - 500000;
g(8,1) = Fn - 0.32;
g(9,1) = - KB - BMT + KG + 0.07*B; %from the older reference

f = annual_cargo_capacity;

val = f + penalty_coef*sum(max(g,0).^2);

end

