A flexible layered control policy for resource allocation in a sensor grid