The document proposes a scheme to optimize fog computing for industrial IoT applications using a Hidden Markov Model. It aims to enable fog-based systems to self-manage through self-configuration, self-optimization, and self-healing with minimal human intervention. The proposed scheme would use a Hidden Markov Model sitting in the edge node to automatically change the network state if performance indicators do not meet requirements. The states considered are distributed, hybrid, and centralized based on available resources and connectivity to optimize latency, network usage, and backhaul link consumption.