Objetive: The operations associated with loading and unloading of container ships demand the use of quay cranes that represent one of the most expensive resources of a maritime terminal. Therefore, the assignment of cranes to ships must be optimized. This article proposes a mathematical model to optimize the decision of assignment of cranes to ships, considering the behavior of tides, which is a not commonly considered factor in the scientific literature for similar problems. Metodology: A mixed integer linear mathematical model was designed and tested for the actual case of a container terminal in Buenaventura-Colombia with satisfactory results. Results: With the available capacity the model allows to mobilize up to 2800 containers per half day, while the number of containers per ship in the real case does not exceed 2000 units. Conclusions: The consideration of tides, combined with downtime penalty cost can allow using smaller number of cranes with savings in energy cost.