/Optimal-process-planning

An algorithm aimed at optimal processes planning / Алгоритм, нацелнный на оптимальное планирование процессов

Primary LanguageGo

Optimal process planning

An algorithm aimed at optimal processes planning is presented to your attention. Formally, we describe the problem. Let there be 1 files that need to be processed by preloading into memory. For memory, the limit is put forward in the form of a total, simultaneously used memory equal to 2. Then, at a time, there may be files in memory, the total volume which does not exceed 3. I.e.

4

where5 is the maximum amount of memory that will be used for processing 7 -th file.

In addition, at the same time there can be no more memory in 6 files, i.e. 7.

Our task is to minimize the total execution time, given that the set of files is updated after complete the processing of one of the previous files. The algorithm for selecting the following file is as follows:

  • Select all possible files in decreasing order of processing time
  • If the next file does not fit into memory, then the file of the maximum size from the possible
  • If no files can be added, it is proposed to process the files

Оптимальное планирование процессов

Вашему вниманию представляется алгоритм, нацелнный на оптимальное планирование процессов. Формально опишем задачу. Пусть есть 1 файлов, которые требуется обработать, предварительно загрузив в память. Для памяти выдвигается ограничение в виде суммарно, одновременно используемой памяти, равной 2. Тогда, единовременно, в памяти могут находиться файлы, суммарный объём которых не превышает 3. Т.е.

4

где 5 - максимальный объём памяти, который будет использоваться для обработки 7-го файла.

Кроме того, одновременно в памяти не может находиться более 6 файлов, т.е. 7.

В нашей задаче требуется минимизировать суммарное время выполнения, учитывая, что набор файлов обновляется после завершения обработки одного из предыдущих файлов. Алгоритм выбора следующего файла состоит в следующем:

  • Выбрать все возможные файлы в порядке убывания времени их обработки
  • Если следующий файл не умещается в память, то выбирается файл максимального объёма из возможных
  • Если ни одни файл добавить не удаётся, то предлагается обработать файлы

Examples

Let's show example of usage:

type Processor struct {
}

func (p *Processor) AppendFiles(filesForProcess scheduler_pkg.FileSlice) {

}

func (p *Processor) Process() int {
	// Processing filesForProcess ...
	return 0
}

func main() {
	files := scheduler_pkg.FileSlice{
		scheduler_pkg.File{0, 1, 2},
		scheduler_pkg.File{1, 1, 2},
		scheduler_pkg.File{2, 1, 2},
		scheduler_pkg.File{2, 18, 5},
	}
	scheduler, err := scheduler_pkg.NewScheduler(files, 5, 3)
	if err != nil {
		panic(err)
	}
	processor := Processor{}
	filesForProcess := scheduler.GetCurrentFiles()
	// New files will appended for processing
	processor.AppendFiles(filesForProcess)
	for {
		// Processing filesForProcess ...
		finishedFileId := processor.Process()
		// Processing one file was finished
		scheduler.Finished(finishedFileId)
		newFiles, err := scheduler.Next()
		if err != nil {
			panic(err)
		}
		if err == io.EOF {
			break
		}
		// New files will appended for processing
		processor.AppendFiles(newFiles)
	}
}

Literature

  1. Job shop scheduling, Wikipedia
  2. Planning, Wikipedia