Consider the following function: $f: \mathbb{R}^n\rightarrow\mathbb{R}$ $$f(x)=\max_{p\in\mathcal{P}} x^Tp$$ where $\mathcal{P}\in\mathbb{R}^n$ is a nonempty and compact set.
It is easy to see that $f(x)$ is a piecewise convex function but is it true that $f(x)$ has gradients almost everywhere? Any references and counterexamples are very welcome.