A generalised optimal design methodology for distributed energy systems