% Company Controls % Input: % - company(C), for each company C % - owns(X,Y,S), if X owns S% of Y % - checkForMaxControls(C), if the solver must controls if C has the greater % number of controlled companies. % Output: % - controls(X,Y), if the company X controls the company Y. % Author: Mario Alviano. % A company X can control something only if it has at least one direct control. canBeController(X) :- owns(X,Y,_), #sum{S : owns(X,Y,S)} > 50. % A company Y can be controlled only if more than 50% of its stocks is shared by % all the companies. canBeControlled(Y) :- company(Y), #sum{S,X : owns(X,Y,S)} > 50. % Each company controls the stocks directly owned. controls_stock(X,X,Y,S) :- canBeController(X), canBeControlled(Y), owns(X,Y,S). % A company controlling a company Z controls the stock owned by Z. controls_stock(X,Z,Y,S) :- controls(X,Z), canBeControlled(Y), owns(Z,Y,S). % A company controlling more than 50% of the stock of a company Y exerts % controls on Y. controls(X,Y) :- 50 < #sum{S,Z : controls_stock(X,Z,Y,S) }, canBeController(X), canBeControlled(Y). % For each company compute the number of controlled companies. count_controls(X,S) :- canBeController(X), #count{Y : controls(X,Y)} = S. % Check that no company controls more companies than X, if X is the company to % to be checked for maximal controls. :- checkForMaxControls(X), count_controls(X,S), #max{N : count_controls(Y,N)} = SS, SS > S.