The advent of fifth-generation (5G) networks introduces the capability for network slicing, which allows for the creation of multiple, distinct logical network slices on a shared infrastructure, tailored to meet the diverse requirements of different user groups. This study is dedicated to the development and analysis of a resource capacity planning and reallocation model within the context of network slicing, with a particular focus on the dynamics between two service providers managing elastic traffic types such as web browsing. A controller is tasked with assessing the necessity for resource redistribution and devising subsequent capacity planning strategies. To determine an optimal resource capacity for each service provider, we utilize a Markov decision process within a controllable queuing framework. The optimization process is guided by a reward function that adheres to three principles of network slicing: maximum matching for equal resource partitioning, maximum share of signals resulting in resource reallocation, and maximum resource utilization. We employ an artificial neural network (multilayer perceptron) with three layers to find the optimal policy. The state of the system is used as the input layer, and the possible size of the slice for the first provider is the output layer. For the considered scenario of web browsing and group data transfer, we numerically demonstrate the impact of the number of neurons in the hidden layer and the number of training epochs on classification accuracy. We compare the results with those obtained using R. Howard’s iteration. © The Author(s), under exclusive license to Springer Nature Switzerland AG 2024.