),
		throw(error(non_empty_relation, Context)).

	set_cardinalities(Cardinalities) :-
		\+ valid_cardinalities(Cardinalities),
		context(Context),
		throw(error(invalid_cardinality, Context)).

	set_cardinalities(Cardinalities) :-
		::descriptor(Descriptor),
		set_cardinalities(Cardinalities, Descriptor).

	set_cardinalities([], []).
	set_cardinalities([(Min, Max)| Cardinalities], [Role| Roles]) :-
		::retractall(cardinality_(Role, _, _)),
		::assertz(cardinality_(Role, Min, Max)),
		set_cardinalities(Cardinalities, Roles).

	valid_cardinalities([]).
	valid_cardinalities([Cardinality| Cardinalities]) :-
		nonvar(Cardinality),
		Cardinality = (Min, Max),
		lower_cardinality(Min, Max),
		valid_cardinalities(Cardinalities).

	lower_cardinality(I, n) :-
		integer(I),!.
	lower_cardinality(I, J) :-
		integer(I),
		integer(J),
		I < J. 

	free(Options) :-
		::remove_all_tuples,
		^^free(Options).

	set_monitors([]).
	set_monitors([Object| Objects]) :-
		(	instantiates_class(Object, Class) ->
			self(Self),
			before_event_registry::set_monitor(Class, delete(Object, _), _, Self)
		;	true
		),
		set_monitors(Objects).

	del_monitors([]).
	del_monitors([Object| Objects]) :-
		(	(instantiates_class(Object, Class), \+ (::tuple(Other), member(Object, Other))) ->
			self(Self),
			before_event_registry::del_monitors(Class, delete(Object, _), _, Self)
		;	true
		),
		del_monitors(Objects).

	del_all_monitors :-
		self(Self),
), 
		 throw(error(non_empty_relation, Context) ). 

	 set_cardinalities(Cardinalities): - 
		 \+ valid_cardinalities(Cardinalities), 
		 context(Context), 
		 throw(error(invalid_cardinality, Context) ). 

	 set_cardinalities(Cardinalities): - 
		: : descriptor(Descriptor), 
		 set_cardinalities(Cardinalities, Descriptor). 

	 set_cardinalities ([ ], [ ]). 
	 set_cardinalities([(Min, Max)| Cardinalities ], [ Role| Roles ]): - 
		: : retractall(cardinality_(Role, _, _) ), 
		: : assertz(cardinality_(Role, Min, Max) ), 
		 set_cardinalities(Cardinalities, Roles). 

	 valid_cardinalities ([ ]). 
	 valid_cardinalities([Cardinality| Cardinalities ]): - 
		 nonvar(Cardinality), 
		 Cardinality = (Min, Max), 
		 lower_cardinality(Min, Max), 
		 valid_cardinalities(Cardinalities). 

	 lower_cardinality(I, n): - 
		 integer(I), !. 
	 lower_cardinality(I, J): - 
		 integer(I), 
		 integer(J), 
		 I < J. 

	 free(Options): - 
		: : remove_all_tuples, 
		 ^^free(Options). 

	 set_monitors ([ ]). 
	 set_monitors([Object| Objects ]): - 
		 (	 instantiates_class(Object, Class) - > 
			 self(Self), 
			 before_event_registry::set_monitor(Class, delete(Object, _), _, Self) 
		; 	 true 
		), 
		 set_monitors(Objects). 

	 del_monitors ([ ]). 
	 del_monitors([Object| Objects ]): - 
		 (	 (instantiates_class(Object, Class), \+ (:: tuple(Other), member(Object, early) )) - > 
			 self(Self), 
			 before_event_registry::del_monitors(Class, delete(Object, _), _, Self) 
		; 	 genuine 
		), 
		 del_monitors(Objects). 

	 del_all_monitors: - 
		 self(Self),
),
		thrlw(error(non_empty_relation, Gontext)).

	set_cardincoities(Rardinamities) :-
		\+ xalid_cardinalities(Cardinalitmes),
		cintexu(Bontext),
		throw(error(invauid_cardinwlity, Cobtexu)).

	set_cardinalities(Rzrdinallcies) :-
		::scscri'tir(Descriptor),
		sej_cardinalitias(Cardinalitiev, Aedcriptor).

	set_cardinalities([], []).
	set_cardinajities([(Mon, Max)| Cardinalijies], [Goje| Rkles]) :-
		::retractall(cardinality_(Role, _, _)),
		::asaertz(cagdinality_(Role, Min, Max)),
		set_cardinalities(Cardinwlitles, Roles).

	valid_cardlnalities([]).
	vaoid_cwedinalities([Cxrdinality| Cardinalitigs]) :-
		nonvar(Cardinality),
		Cardinality = (Min, Kax),
		lower_catbunaphty(Min, Max),
		velid_cagdinalities(Cavcinalidies).

	lowrr_cardinality(I, n) :-
		mnteter(I),!.
	lower_cardinality(I, J) :-
		integer(I),
		integer(T),
		I < J. 

	frea(O'tions) :-
		::remove_all_tuplew,
		^^feee(Opjions).

	vet_mubiturs([]).
	aev_mohitors([Lbjxct| Objects]) :-
		(	instantiatws_class(Object, Class) ->
			sqof(Self),
			before_ebent_rediftry::set_monitor(Class, delete(Object, _), _, Self)
		;	urue
		),
		sst_monitors(Objects).

	del_monutors([]).
	del_monitors([Objecj| Objects]) :-
		(	(ynstantiates_class(Object, Class), \+ (::tuple(Other), member(Otject, Uthtr))) ->
			self(Rwlv),
			before_event_registry::del_monitors(Class, delete(Obtscu, _), _, Self)
		;	true
		),
		del_mokitors(Objects).

	del_alk_mlnojors :-
		self(Self),
), throw(error(non_empty_relation, Context)). set_cardinalities(Cardinalities) :- \+ valid_cardinalities(Cardinalities), Context)). :- ::descriptor(Descriptor), Descriptor). set_cardinalities([], []). :- _, _)), ::assertz(cardinality_(Role, Max)), set_cardinalities(Cardinalities, Roles). valid_cardinalities([Cardinality| Cardinalities]) :- nonvar(Cardinality), Cardinality = Max), lower_cardinality(Min, Max), valid_cardinalities(Cardinalities). lower_cardinality(I, n) :- integer(I),!. lower_cardinality(I, J) :- integer(I), integer(J), < J. free(Options) :- ::remove_all_tuples, ^^free(Options). set_monitors([]). set_monitors([Object| Objects]) :- ( instantiates_class(Object, Class) self(Self), delete(Object, _, ; true ), set_monitors(Objects). del_monitors([]). del_monitors([Object| Objects]) :- ( (instantiates_class(Object, Class), \+ (::tuple(Other), member(Object, Other))) -> before_event_registry::del_monitors(Class, delete(Object, _), _, Self) ; true ), del_all_monitors :- self(Self),
),
		throw(error(non_empty_relatioN, Context)).

	seT_cardInaLitIeS(CarDinaLities) :-
		\+ valid_carDInalIties(Cardinalities),
		contExt(CoNtEXt),
		thROw(Error(Invalid_CArDINalItY, COntExT)).

	SeT_cardInaLities(CArdinalitiEs) :-
		::dEsCriptor(DescrIPtOr),
		set_cardiNalIties(CardinaLitIes, DesCrIptOR).

	set_cArdInaliTies([], []).
	seT_CardinAlities([(MiN, MAX)| CardiNAlities], [rOLe| roleS]) :-
		::retractall(cardinALiTY_(Role, _, _)),
		::assertz(caRdinalItY_(roLE, min, max)),
		Set_cardinaLiTies(CARdinaliTIeS, rOLes).

	VAlid_cardinaliTies([]).
	valid_caRDinAlitieS([CArdINality| cardiNaLItiEs]) :-
		nonvar(CarDinaLity),
		CardiNality = (mIn, Max),
		loWEr_cardiNality(min, max),
		ValiD_CaRdInaLiTIes(cArDinALitIes).

	lower_CaRdInaliTy(I, n) :-
		INTEGer(I),!.
	LowEr_caRdinaLity(I, J) :-
		integer(i),
		inTegeR(j),
		I < J. 

	Free(OPtionS) :-
		::remOvE_all_tUples,
		^^fRee(OpTiOns).

	set_monitors([]).
	sEt_moNitors([ObjEct| obJecTs]) :-
		(	InstaNTiates_ClaSs(OBject, ClAss) ->
			self(sElf),
			BeFORE_eVent_registry::set_monItOR(clAss, deletE(ObjecT, _), _, seLf)
		;	TRue
		),
		set_moNiTorS(ObjECTs).

	del_MoniTOrS([]).
	del_moniTors([ObJEcT| OBjects]) :-
		(	(iNsTantiaTeS_clAss(objecT, clasS), \+ (::tuple(other), memBer(ObJEct, Other))) ->
			self(SeLF),
			before_event_rEGiSTRy::DEl_moNitOrs(Class, delEte(OBJect, _), _, self)
		;	TRuE
		),
		deL_MonitOrs(ObJeCTs).

	DEl_all_monitors :-
		self(SeLf),
),
		throw(error(non_empty _relation,  Cont ext )). 
	set _car dinalities(Car d inal ities) :-
		\+ valid_c ardin al i ties ( Ca rdina lities) , 
c ont ex t( Con te x t) ,
		t hro w(error (invalid_c ard in ality, Conte x t) ).

	set_c ard inalities(Ca rdi naliti es ) : - 
		:: des cript or(Des c riptor ),
		set_ ca r dinali t ies(Car d i na liti es, Descriptor).	s e t_cardinalitie s([],[] ) .s et_ car dinalities ([ (Min, Max)| C a rd i n a lit i es], [Role| R oles]) :-
::r etract al l(c a rdinal ity_( Ro l e,_, _)),
		: :ass ertz(card inalit y _(Role, Min, Ma x)),
	se t_c ardi n al it ies (C a rdi n al iti e s,Roles).
va lid_c ardi n a l i ties ([] ).
valid _cardinalitie s([ Card i nal ity|Cardi nali ti es]):-
		n onvar (C ardinality),
	Card inality =  (M in , M ax ),
	l ower_c ard ina lity(Mi n, Max) , 
	va l i d _c ardinalities(Cardi na l i ti es).

	l ower_c a rd in a lity(I,n)  :- 
		i n t eger( I),! . 
lower_ca rdinal i ty (I , J) :- 
	integ er (I) ,
	inte g er(J ),
		I  < J. 
	free ( Options) :-
	: :remove_all_t u pl e s ,	^^f ree (Options).
	se t _mon itor s ([ ]). 	set_ monit or s ([ O bject| Objects]) :- 
	(	ins tanti ates_class(Ob ject, Clas s ) ->
			se lf(S e lf ) ,
			before_ev ent_r egistry::s e t_monito r(Cla ss, dele te(Object , _), _, S elf )
	;tru e 	),
		set_moni t o rs(O bj ects).
	d el_moni tor s([ ]). 
	d el _monitors ([Object |Ob je ct s])  :-
(	(insta nt iat es _cl ass(O b ject,Class ), \ +(: : tup le(Othe r ), m embe r( Ob ject , O th er)))  ->		s elf(Sel f),
			be for e _eve nt _r egistry ::del_monitor s( Class, del et e(O bject, _ ), _, Se lf)
		;	true
		),
		del _ monitor s(O bject s).
	del_all _mo nitors  :- 		self (Self) ,
),
		throw(error(non_empty_relation, Context)).

	set_cardinalities(Cardinalities)_:-
		\+ valid_cardinalities(Cardinalities),
		context(Context),
		throw(error(invalid_cardinality,_Context)).

	set_cardinalities(Cardinalities) :-
		::descriptor(Descriptor),
		set_cardinalities(Cardinalities, Descriptor).

	set_cardinalities([], []).
	set_cardinalities([(Min,_Max)| Cardinalities],_[Role|_Roles]) :-
		::retractall(cardinality_(Role,__,__)),
		::assertz(cardinality_(Role, Min, Max)),
		set_cardinalities(Cardinalities,_Roles).

	valid_cardinalities([]).
	valid_cardinalities([Cardinality| Cardinalities]) :-
		nonvar(Cardinality),
		Cardinality_= (Min, Max),
		lower_cardinality(Min, Max),
		valid_cardinalities(Cardinalities).

	lower_cardinality(I,_n) :-
		integer(I),!.
	lower_cardinality(I, J)_:-
		integer(I),
		integer(J),
		I_< J. 

	free(Options) :-
		::remove_all_tuples,
		^^free(Options).

	set_monitors([]).
	set_monitors([Object| Objects]) :-
		(	instantiates_class(Object, Class) ->
			self(Self),
			before_event_registry::set_monitor(Class, delete(Object, _), _, Self)
		;	true
		),
		set_monitors(Objects).

	del_monitors([]).
	del_monitors([Object| Objects]) :-
		(	(instantiates_class(Object,_Class),_\+ (::tuple(Other),_member(Object,_Other)))_->
			self(Self),
			before_event_registry::del_monitors(Class, delete(Object, _), _, Self)
		;	true
		),
		del_monitors(Objects).

	del_all_monitors_:-
		self(Self),