@fengjingchao 
We should give assign each `replica` an ID. but the ID might not be continuous. 
Chang N to `[]Ids`.
Change InstanceMatrix related stuff to use map. Or you can wrapper an array for performance.