Direct calculation of average and marginal costs from the productive structure of an energy system.