How to write constraint, where A will be divisible by 6 and it it’s true, then B should be nearest to A.
In reply to kmishra:
Here is most of your constrain, except I don’t know what “B should be nearest to A” means.
(A % 6) ==0 -> (????)
Can you give some examples of values you are looking for that meet your constraint?
In reply to kmishra:
From the statement which is “nearest”, I guess that you have another variable(s) other than A and B. The case you state says that B must be nearest to A, so if we assume that you have a sequence item which is named as “dummy_seq_item”, you can write sth like this:
--------------Your seq_item code-------------------
class dummy_seq_item extends uvm_sequence_item;
`uvm_object_utils(dummy_seq_item)
function new(string name=“dummy_seq_item”);
super.new(name);
endfunction
rand int A;
rand int B;
rand int C;
constraint A_is_first{
solve A before B;
solve A before C;
}
constraint which_is_closer{
((A%6) == 0 ) → ( B>C );
};
endclass
let’s say, if you have D, E and etc. other than B and C, you can write a swap function instead of right hand side of the constraint. If it returns 1, constraint will be valid.
In reply to yuksek:
In reply to kmishra:
From the statement which is “nearest”, I guess that you have another variable(s) other than A and B. The case you state says that B must be nearest to A, so if we assume that you have a sequence item which is named as “dummy_seq_item”, you can write sth like this:
--------------Your seq_item code-------------------
class dummy_seq_item extends uvm_sequence_item;
`uvm_object_utils(dummy_seq_item)
function new(string name=“dummy_seq_item”);
super.new(name);
endfunction
rand int A;
rand int B;
rand int C;
constraint A_is_first{
solve A before B;
solve A before C;
}
constraint which_is_closer{
((A%6) == 0 ) → ( B>C );
};
endclass
let’s say, if you have D, E and etc. other than B and C, you can write a swap function instead of right hand side of the constraint. If it returns 1, constraint will be valid.
Thanks for the suggestions, got some idea now.