I agree in many instances with Symbeline.
The problem you face is hormonal and it’ll stay in your head for a long while.
It’s nature hurting you, torturing you for not achieving what it wants you to, which is having the mate you identified as suitable.
The best solution is shielding yourself from the hormones. Doing other stuff, enjoying life.
Also yes, enjoy masturbation but be aware that you better shouldn’t masturbate when you’re in a terrible mood as it will more likely worsen your mood. Cheer yourself up, relax, and then you can make that feeling stronger with masturbation.
Another important thing that you should consider is personal growth. The path to achieve things and the wonderful feeling of achievement will distract you from your worries and at the same time make you a more interesting person for others, including potential lovers.
If you’re boring then expand your horizon, learn new things, learn new ways of amusement, amuse others, be part of something, etc.
If you’re unhealthy and/or obese, work on becoming better/fitter again, work yourself back into shape, get on a diet that holds the vitamins you need, etc.
The only good way, is forward. Stop to smell the roses, but also move on to discover more of them.