HOMER Knowledge Base
Optimization
HOMER does not optimize the system taking into account the sizing of elements. The optimization is more concerned with the total cost of the project, i.e. it looks for the cheapest feasible system. It means that the user must have a first accurate knowledge of the system he wants to implement and that HOMER won't optimize for example whether a fuel cell of 2 or 5kW is better for the considered load.
HOMER does indeed search for the least cost feasible system. But you can constrain that search in many ways. In your example of the 2 kW or 5 kW fuel cell for example, I suspect you are thinking of a situation where the peak load is something like 4 kW and HOMER is recommending the 2 kW fuel cell, which requires assistance from a battery to meet the peak loads. But you want the fuel cell to be at least as large as the peak load. You can enforce that constraint using a checkbox in the System Control Inputs window. If you uncheck the box labeled "Allow systems with generator capacity less than peak load" then HOMER will consider the 2 kW fuel cell to be infeasible for a system with a 4 kW peak load.
Many other constraints allow you to, for example, limit fuel consumption or emissions or battery life. In all cases, HOMER will search for the least cost system that satisfies all the constraints that you have imposed.