We computationally demonstrate a method to control Marangoni-driven flows and create patterns with sharp features on polymer films by optimizing the spatial variation of surface energy or tension. This Marangoni-driven patterning (MDP) uses the variations in surface tension to drive fluid flow. By selectively exposing a thin polymer film to UV light, a photochemical reaction takes place, which subsequently alters the surface tension of the polymer film in the exposed regions. On heating above its glass transition temperature, the polymer flows from regions of lower to higher surface tension to form hill-and-valley features. A barrier to advancing the application of MDP is that the flow will often dull sharp features and degrade the fidelity of the desired pattern. To compensate a pixel-based optimization of the surface energy or equivalently, the photoexposure pattern is developed. A genetic algorithm is used to search for the optimum photoexposure pattern based on simulations of the flow, which includes Marangoni and capillary forces and diffusion of the surface tension promoter. The optimization of the photoexposure pattern significantly improves the fidelity of the desired final pattern for a wide range of annealing temperatures and times. Guidelines for successful MDP are identified based on ratios of characteristic times for the Marangoni and capillary flows and lateral diffusion.