For a very very long time I was researching why my mac was restarting at random times. Every website that explains this issue has about 5 to 10 different things to try, but nothing worked.
I was quite sure it was based on the graphic card - likely faulty. The graphics card switching caused the mac to restart. I was sure of this because it often restarted when I video was running. I tried running gfxCardStatus and setting it to Integrated, but it wouldn't allow me. So I left this issue for a while.
Recently I came across this forum which explains that in the first few comments - that it can't change to "integrated" since a dependency is running (like when you install a program and you are supposed to close your other programs to let it run without issues). But the weird thing is that gfxCardStatus (the program itself!) is a dependency with this version of the MaxOS Sierra.
If you search on that page "BenChesh", he explains that he modified the program to force it to change its settings to "Integrated". I tried it and it seems to be good so far. Thanks Ben Cheshire!
You simply download his link and run it and it works.
Please leave a comment below if this fixed your Max restarting issue too!