priority

package
v0.0.0-...-24daea3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Copyright 2022 The ChromiumOS Authors Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BoardInfo

type BoardInfo = floatPriority

BoardInfo represents a (chosen) board and its index in the original input boards list. This is done by exposing relevant floatPriority fields to external packages. Index is needed for multi-dut tests where the input may have repeating boards for different multi-dut combinations.

func (*BoardInfo) GetBoard

func (p *BoardInfo) GetBoard() string

GetBoard exposes the internal field: board.

func (*BoardInfo) GetIndex

func (p *BoardInfo) GetIndex() int

GetIndex exposes the internal field: index.

type RandomWeightedSelector

type RandomWeightedSelector struct {
	// contains filtered or unexported fields
}

RandomWeightedSelector selects from a list of boards, with a random choice weighted by BoardPriorities. The algorithm is as follows:

  1. The sign of priorities is flipped, so that the board with the most negative configured priority now has the most positive priority.
  2. If a priority is not defined for a board, it is implicitly 0, as defined in the BoardPriority proto comment.
  3. Priorities are shifted so that the minimum priority is 1.
  4. Priorities are divided by the sum of the shifted priorities. At this point, the priorities form a probability distribution (each is in the range (0, 1], and they sum to 1). Each board's probability is proportional to its original configured priority, i.e. the board with the most negative configured priority has the highest probability.
  5. Sample a board from the probability distribution.

func NewRandomWeightedSelector

func NewRandomWeightedSelector(rand *rand.Rand, boardPriorityList *testplans.BoardPriorityList) *RandomWeightedSelector

NewRandomWeightedSelector returns a RandomWeightedSelector based on boardPriorityList.

func (*RandomWeightedSelector) Select

func (rw *RandomWeightedSelector) Select(pool string, boards []string) (string, error)

Select is a wrapper of SelectPriority. TODO(mingkong): remove the wrapper once the code is fully migrated to the new method signature.

func (*RandomWeightedSelector) SelectPriority

func (rw *RandomWeightedSelector) SelectPriority(pool string, boards []string) (BoardInfo, error)

SelectPriority randomly chooses a board from boards, with the probability a board is chosen proportional to its configured probability. Returns a BoardInfo object that contains the board name and its index in the input boards list. The index can be used to choose the board for companions accordingly to the board selection of the primary device in multi-dut tests. It is likely that multi-dut config to have repeating values in the input boards list, which means the priority for repeating boards is double weighted using the existing algorithm. TODO(mingkong) evaluate the side effect and check if global priority config (http://shortn/_NmJHlrSPiZ) should be used by multi-dut tests, which has its own specialized pools.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL