Package dev.nm.misc.algorithm
Class ActiveSet
- java.lang.Object
-
- dev.nm.misc.algorithm.ActiveSet
-
public class ActiveSet extends Object
This class keeps track of the active and inactive indices.
-
-
Constructor Summary
Constructors Constructor Description ActiveSet(boolean sorted)
Construct a working set of active/inactive indices.ActiveSet(boolean sorted, int[] indices)
Construct a working set of active/inactive indices.ActiveSet(boolean sorted, Collection<Integer> indices)
Construct a working set of active/inactive indices.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
activeSize()
Get the number of active indices.void
addActive(int j)
Add an active constraint by index.void
addActive(int[] indices)
Add active indices.void
addActive(Collection<Integer> indices)
Add active indices.void
addInactive(int j)
Add an inactive constraint by index.void
addInactive(int[] indices)
Add inactive indices.void
addInactive(Collection<Integer> indices)
Add inactive indices.boolean
containActive(int j)
Check if the active set contains a certain index.boolean
containInactive(int j)
Check if the inactive set contains a certain index.int
getActive(int i)
Get the i-th active index.int[]
getActiveIndices()
Get all active indices.int
getInactive(int i)
Get the i-th inactive index.int[]
getInactiveIndices()
Get all inactive indices.int
inactiveSize()
Get the number of inactive indices.void
removeActive(int j)
Remove an active index.void
removeActiveByIndex(int i)
Remove an active constraint by index.void
removeInactive(int j)
Remove an inactive index.void
removeInactiveByIndex(int i)
Remove an active constraint by index.String
toString()
-
-
-
Constructor Detail
-
ActiveSet
public ActiveSet(boolean sorted)
Construct a working set of active/inactive indices.- Parameters:
sorted
- indicator of whether the indices are sorted
-
ActiveSet
public ActiveSet(boolean sorted, Collection<Integer> indices)
Construct a working set of active/inactive indices.- Parameters:
sorted
- indicator of whether the indices are sortedindices
- the active indices
-
ActiveSet
public ActiveSet(boolean sorted, int[] indices)
Construct a working set of active/inactive indices.- Parameters:
sorted
- indicator of whether the indices are sortedindices
- the active indices
-
-
Method Detail
-
addActive
public void addActive(Collection<Integer> indices)
Add active indices.- Parameters:
indices
- a collection of active constraint indices
-
addActive
public void addActive(int[] indices)
Add active indices.- Parameters:
indices
- an array of active constraint indices
-
addInactive
public void addInactive(Collection<Integer> indices)
Add inactive indices.- Parameters:
indices
- a collection of inactive constraint indices
-
addInactive
public void addInactive(int[] indices)
Add inactive indices.- Parameters:
indices
- an array of inactive constraint indices
-
addActive
public void addActive(int j)
Add an active constraint by index.- Parameters:
j
- an index of an active constraint
-
addInactive
public void addInactive(int j)
Add an inactive constraint by index.- Parameters:
j
- an index of an inactive constraint
-
removeActive
public void removeActive(int j)
Remove an active index.- Parameters:
j
- an active index to be removed.
-
removeInactive
public void removeInactive(int j)
Remove an inactive index.- Parameters:
j
- an inactive index to be removed.
-
removeActiveByIndex
public void removeActiveByIndex(int i)
Remove an active constraint by index.- Parameters:
i
- an active index, counting from 1
-
removeInactiveByIndex
public void removeInactiveByIndex(int i)
Remove an active constraint by index.- Parameters:
i
- an inactive index, counting from 1
-
activeSize
public int activeSize()
Get the number of active indices.- Returns:
- the number of active indices
-
inactiveSize
public int inactiveSize()
Get the number of inactive indices.- Returns:
- the number of inactive indices
-
containActive
public boolean containActive(int j)
Check if the active set contains a certain index.- Parameters:
j
- an index of an active constraint- Returns:
true
if the active set containsj
-
containInactive
public boolean containInactive(int j)
Check if the inactive set contains a certain index.- Parameters:
j
- an index of an inactive constraint- Returns:
true
if the inactive set containsj
-
getActiveIndices
public int[] getActiveIndices()
Get all active indices.- Returns:
- all active indices
-
getInactiveIndices
public int[] getInactiveIndices()
Get all inactive indices.- Returns:
- all inactive indices
-
getActive
public int getActive(int i)
Get the i-th active index.- Parameters:
i
- an index.- Returns:
- the i-th active index
-
getInactive
public int getInactive(int i)
Get the i-th inactive index.- Parameters:
i
- an index, counting from 1- Returns:
- the i-th inactive index
-
-