A comprehensive tool for efficient design and operation of polygeneration-based energy lgrids serving a cluster of buildings. Part I: Description of the method