(!****************************************************** Mosel Example Problems ====================== file k4even.mos ``````````````` Placing a given number of chips on a 4x4 grid such that every row and every column contains an even number of chips. - Enumerating multiple solutions - (c) 2008 Fair Isaac Corporation author: S. Heipcke, Mar. 2002, rev. June 2011 *******************************************************!) model "K-4 Even" uses "mmxprs" declarations POS = 1..4 ! Positions in a row/column NCHIP = 10 ! Number of chips place: array(POS,POS) of mpvar ! 1 if chip at the position, 0 otherwise row, column: array(POS) of mpvar ! Chips per row/column divided by 2 end-declarations ! Total number of chips sum(r,c in POS) place(r,c) = NCHIP ! Even number of chips in all rows and columns forall(r in POS) sum(c in POS) place(r,c) = 2*row(r) forall(c in POS) sum(r in POS) place(r,c) = 2*column(c) forall(r,c in POS) place(r,c) is_binary forall(r in POS) do row(r) is_integer; row(r) <= 2 column(r) is_integer; column(r) <= 2 end-do ! Solve the problem: no objective setparam("XPRS_enummaxsol", 100) ! Max. number of solutions to be saved minimize(XPRS_ENUM,0) ! Solution printing forall(i in 1..getparam("XPRS_enumsols")) do selectsol(i) ! Select a solution from the pool writeln("Solution ", i) forall(r in POS) do forall(c in POS) write( if(getsol(place(r,c))>0, "X ", ". ") ) writeln end-do end-do end-model