Resource allocation, trading and adaptation in self-managing systems