#################################################################
##  CS 3600 (Winter 2025), Assignment #1                       ##
##  Program File Name: myCSTMSCClasses.py                      ##
##       Student Name: Todd Wareham                            ##
##         Login Name: harold                                  ##
##              MUN #: 8008765                                 ##
#################################################################

## Provided classes for Assigment #1.
##
##      *** DO NOT CHANGE THE CODE IN THIS FILE ***
##


## Item class; in the context of the MSC problem, an Item object contains a 
##  subset s in S of the specified integer element-set I along with s's number 
##  in the subsets of S given in the input file.

## Attributes:
##   int[]    itemContents
##   int      itemNum

class Item:

    def __init__(self, iCon, iNum):
       self.itemContents = iCon
       self.itemNum = iNum

    def getItemContents(self):
       return(self.itemContents)

    def getItemNum(self):
       return(self.itemNum)

    def __str__(self):
       return(str(self.itemNum) + ": " + str(self.itemContents))


## Problem class; in the context of the MSC problem, a Problem object 
##  contains the set S of subsets of the specified integer element-set I 
##  (each of which is encoded as an Item object) and the maximum 
##  integer value in I.

## Attributes:
##   Item[]    items
##   int       numElements

class Problem:

   def __init__(self, filename):
      f = open(filename, "r+")
      self.numElements = int(f.readline().strip().split()[1])
      numSubsets = int(f.readline().strip().split()[1])
      self.items = []
      for i in range(numSubsets):
          itemList = []
          for x in f.readline().split():
             itemList.append(int(x))
          self.items.append(Item(itemList, i + 1))
      f.close()

   def getItems(self):
      return(self.items)

   def getItem(self, i):
      return(self.items[i - 1])

   def getNumElements(self):
      return(self.numElements)

   def printDesc(self):
      print(str(self.numElements) + " Elements (Integers in {1,2,...," +
                 str(self.numElements) + "})")
      print(str(len(self.items)) + " Subsets:")
      for i in range(len(self.items)):
          print(str(self.items[i]))
    

## Solution class; in the context of the MSC problem, a Solution object 
##  contains the subsets of S in the solution (each of which is encoded as
##  an Item object) and a reference to the solution's associated Problem
##  object.

## Attributes:
##   Item[]    solutionItems
##   Problem   problem

class Solution:

   def __init__(self, prob):
      self.solutionItems = []
      self.problem = prob

   def getItems(self):
      return(self.solutionItems)

   def getProblem(self):
      return(self.problem)

   def addItem(self, item):
      self.solutionItems.append(item)

   def __str__(self):
      if (len(self.solutionItems) == 0):
         s = "ZZZ"
      else:
         s = str(self.solutionItems[0].getItemNum())
         for x in self.solutionItems[1:]:
            s = s + " " + str(x.getItemNum())
      return(s)

