Cloud computing plays an essential role in development of the Internet of Things, which provides data processing and storage services. Fog computing is the evolution of cloud computing, which helps provide solutions to cloud computing challenges such as latency, location awareness, and real-time mobility support. Fog computing fills the gap between the cloud and IoT devices within the close vicinity of IoT devices. So, computation, networking, storage, data management, and decision making occur along the path between the cloud and IoT devices. The automatic and intelligent management of fog node resources and achieving an effective scheduling policy in the computing model is a necessary requirement and will lead to the improvement of the overall performance of fog computing. Some optimization problems are modeled by mixed-integer nonlinear programming (MINLP). In this paper, a model, i.e. an MINLP optimization problem on fog computing, is designed. Our model has two goals: to increase Cost Performance as well as to reduce energy consumption. Cost Performance is the price, users are charged as benefit/revenue. In other words Cost Performance is defined as the ratio of the average data rate of each user to its cost. Then the exact mathematical method with the GAMS program was used to prove its logical process. In the next step, we solved the model with Genetic Algorithm (GA), Particle Swarm Optimization (PSO), Simulated Annealing+GA (SA+GA), Teaching–Learning-Based Optimization (TLBO), Grey Wolf Optimizer (GWO), Grasshopper Optimization Algorithm (GOA), and random method. According to the TOPSIS comparison, the SA+GA method with a value of 0.23 is the best compared to other methods. Then GWO, GA, TLBO, PSO, and GOA methods are better, respectively.