The problem studied in this paper takes as input data a set of lines forming a railway network, and an origin-destination (OD) matrix. The OD pairs may use either the railway network or an alternative transportation mode. The objective is to determine the frequency/headway of each line as well as its number of carriages, so that the net profit of the railway network is maximized. We propose a mixed integer non-linear programming program for this problem. Because of the computational intractability of this model, we develop four algorithms: a mixed integer linear programming (MIP) model, a MIP-based iterative algorithm, a shortest-path based algorithm, and a local search. These four algorithms are tested and compared over a set of randomly generated instances. An application over a case study shows that only the local search heuristic is capable of dealing with large instances.