示例#1
0
        void RemovePerson(Person person)
        {
            Location    location = person.Location;
            MatrixEntry entry    = GetEntryByIndex(location.Index);

            entry.Occupation = new Occupation(location, null);
        }
示例#2
0
        public Region(int top, int left, int width, int height, int rect_size)
        {
            top_          = top;
            left_         = left;
            width_        = width;
            height_       = height;
            rect_size_    = rect_size;
            matrix_       = new MatrixEntry[height_][];
            matrix_index_ = new Dictionary <int, Tuple <int, int> >();
            rand_         = new Random();

            int next_top = top, next_left = left;

            for (int i = 0; i < height_; i++)
            {
                MatrixEntry[] rects = matrix_[i] = new MatrixEntry[width_];
                for (int j = 0; j < width_; j++)
                {
                    int      index    = j + i + (width_ - 1) * i + 1;
                    Location location = new Location(this, index);
                    rects[j] = new MatrixEntry {
                        Rect       = new Rect(next_top, next_left, rect_size),
                        Occupation = new Occupation(location, null)
                    };
                    matrix_index_[index] = new Tuple <int, int>(i, j);
                    next_left            = next_left + rect_size;
                }

                next_top  = next_top + rect_size;
                next_left = left;
            }

            doors_ = new Dictionary <int, Location>();
        }
示例#3
0
        public async Task CreateMatrixForNewAddress(int addressId)
        {
            var newAddress = _addressRepository.GetSingle(a => a.Id == addressId);
            var addresses  = _addressRepository.All();

            foreach (var address in addresses)
            {
                try
                {
                    var fromNew = new MatrixEntry()
                    {
                        OriginId = newAddress.Id, DestinationId = address.Id, ObjectState = ObjectState.Added
                    };
                    fromNew.Value = await GetUpdatedMatrixEntryValue(newAddress, address);

                    var toNew = new MatrixEntry()
                    {
                        OriginId = address.Id, DestinationId = newAddress.Id, ObjectState = ObjectState.Added
                    };
                    toNew.Value = await GetUpdatedMatrixEntryValue(address, newAddress);

                    _matrixRepository.InsertOrUpdate(new MatrixEntry[] { fromNew, toNew });
                }
                catch (Exception)
                {
                    throw;
                }
            }
        }
示例#4
0
        /// <summary>
        /// Transform to list of matrix entries.
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        public static List <MatrixEntry <double> > ToMatrixEntries(this List <Rating> ratings)
        {
            List <MatrixEntry <double> > entries = new List <MatrixEntry <double> >();

            foreach (var r in ratings)
            {
                MatrixEntry <double> e = new MatrixEntry <double>(r.UserId, r.ItemId, r.Score);
                entries.Add(e);
            }
            return(entries);
        }
示例#5
0
 public IEnumerable <Location> GetEmptyLocations()
 {
     for (int i = 0; i < height_; i++)
     {
         for (int j = 0; j < width_; j++)
         {
             MatrixEntry entry = matrix_[i][j];
             if (entry.Occupation.Person == null)
             {
                 yield return(entry.Occupation.Location);
             }
         }
     }
 }
示例#6
0
        public Location PlacePerson(Person person, int index)
        {
            RemovePerson(person);

            // If the person moves to a door location, it should be transported
            // to the region that is close to it.
            if (doors_.TryGetValue(index, out var door))
            {
                return(door);
            }

            MatrixEntry entry    = GetEntryByIndex(index);
            Location    location = entry.Occupation.Location;

            entry.Occupation = new Occupation(location, person);

            return(location);
        }
示例#7
0
        public IEnumerable <IMatrixEntry> GetEntries(Predicate <IMatrixEntry> predicate)
        {
            lock (locker)
            {
                var results = new List <IMatrixEntry>();
                for (int i = 0; i < JA.Count; i++)
                {
                    var row    = GetRowByAIndex(i);
                    var column = JA.ElementAt(i).Value;
                    var count  = A.ElementAt(i).Value;

                    var rowWord    = allWords.ElementAt(row);
                    var columnWord = allWords.ElementAt(column);
                    var entry      = new MatrixEntry(rowWord, columnWord, count);
                    if (predicate.Invoke(entry))
                    {
                        results.Add(entry);
                    }
                }
                return(results);
            }
        }
			public MatrixEntry ME;	// Used at runtime to contain data values	
			public WorkClass()
			{
				ME=null;
			}
            internal MatrixEntry ME; // Used at runtime to contain data values

            #endregion Fields

            #region Constructors

            internal WorkClass()
            {
                ME=null;
            }
示例#10
0
		void RunRowHeaders(Report rpt, WorkClass wc, MatrixEntry m, MatrixCellEntry[,] matrix, Rows _Data, ref int iRow, int iColumn, int level)
		{
			foreach (MatrixEntry ame in m.GetSortedData(rpt))
			{
				matrix[iRow, iColumn] = RunGetRowHeader(rpt, ame, _Data);
				matrix[iRow, iColumn].Height = RunRowHeight(iRow);
				matrix[iRow, iColumn].Width = ame.RowGroup.Width == null? 0: ame.RowGroup.Width.Points;
				if (ame.GetSortedData(rpt) != null)
				{
					RunRowHeaders(rpt, wc, ame, matrix, _Data, ref iRow, iColumn+1, level+1);
				}
				else
					iRow++;
			}

			RowGrouping rg = (RowGrouping) (_RowGroupings.Items[level]);
			// do we need to subtotal this
			if (rg.DynamicRows != null &&
				rg.DynamicRows.Subtotal != null)
			{					   // TODO need to loop thru static??
				ReportItem ri = rg.DynamicRows.Subtotal.ReportItems.Items[0];	
				matrix[iRow, iColumn] = new MatrixCellEntry(_Data, ri);
				matrix[iRow, iColumn].Width = rg.Width.Points;
				matrix[iRow, iColumn].Height = RunRowHeight(iRow);
				RunRowStaticHeaders(rpt, wc, matrix, _Data, iRow, level);
				iRow += Math.Max(1,this.RowGroupings.StaticCount);
			}
		}
示例#11
0
		void RunDataRow(Report rpt, WorkClass wc, MatrixEntry rm, MatrixEntry cm, MatrixCellEntry[,] matrix, Rows _Data, ref int iRow, int iColumn, int level)
		{
			int saveColumn;
			int headerRows = _ColumnGroupings.Items.Count;	// number of column headers we have
			int rgsCount = this.RowGroupings.StaticCount;	// count of static row groups
			foreach (MatrixEntry ame in rm.GetSortedData(rpt))
			{
				if (ame.RowGroup != LastRg)
				{
					RunDataRow(rpt, wc, ame, cm, matrix, _Data, ref iRow, iColumn, level+1);
					continue;
				}
				saveColumn = iColumn;
				int rowcell = rgsCount == 0? 0: (iRow - headerRows) % rgsCount;
				RunDataColumn(rpt, wc, ame, cm, matrix, _Data, iRow, ref saveColumn, 0, rowcell);
				iRow++;
			}
			// do we need to subtotal this?
			RowGrouping rg = (RowGrouping) (_RowGroupings.Items[level]);
			if (rg.DynamicRows != null &&
				rg.DynamicRows.Subtotal != null)
			{
				for (int i=0; i < this.CountMatrixRows; i++)
				{
					saveColumn = iColumn;
					RunDataColumn(rpt, wc, rm, cm, matrix, _Data, iRow, ref saveColumn, 0, i);
					iRow++;
				}
			}
		}
示例#12
0
		void RunDataColumn(Report rpt, WorkClass wc, MatrixEntry rm, MatrixEntry cm, MatrixCellEntry[,] matrix, Rows _Data, int iRow, ref int iColumn, int level, int rowcell)
		{
			BitArray andData;
			MatrixRow mr = this.MatrixRows.Items[rowcell] as MatrixRow;
			float height = mr.Height == null? 0: mr.Height.Points;

			foreach (MatrixEntry ame in cm.GetSortedData(rpt))
			{
				if (ame.ColumnGroup != LastCg)
				{
					RunDataColumn(rpt, wc, rm, ame, matrix, _Data, iRow, ref iColumn, level+1, rowcell);
					continue;
				}
				andData = new BitArray(ame.Rows);	// copy the data
				andData.And(rm.Rows);				//  because And is destructive
				matrix[iRow, iColumn] = RunGetMatrixCell(rpt, ame, iRow, _Data, andData, 
						Math.Max(rm.FirstRow, ame.FirstRow),
						Math.Min(rm.LastRow, ame.LastRow));
				matrix[iRow, iColumn].Height = height;
				matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]);
				matrix[iRow, iColumn].ColumnME = ame;
				matrix[iRow, iColumn].RowME = rm;
				
				iColumn++;
			}
			// do we need to subtotal this?
			ColumnGrouping cg = (ColumnGrouping) (_ColumnGroupings.Items[level]);
			if (cg.DynamicColumns != null &&
				cg.DynamicColumns.Subtotal != null)
			{
				andData = new BitArray(cm.Rows);	// copy the data
				andData.And(rm.Rows);				//  because And is destructive
				for (int i=0; i < this.CountMatrixCells; i++)
				{
					matrix[iRow, iColumn] = RunGetMatrixCell(rpt, cm, rowcell, i, _Data, andData, 
						Math.Max(rm.FirstRow, cm.FirstRow),
						Math.Min(rm.LastRow, cm.LastRow));
					matrix[iRow, iColumn].Height = height;
					matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]);
					matrix[iRow, iColumn].ColumnME = cm;
					matrix[iRow, iColumn].RowME = rm;
					iColumn++;
				}
			}
		}
示例#13
0
		MatrixCellEntry RunGetColumnHeader(Report rpt, MatrixEntry me, Rows _Data)
		{
			ReportItem ri;
			if (me.ColumnGroup.StaticColumns != null)
			{	// Handle static column reference
				StaticColumn sc = me.ColumnGroup.StaticColumns.Items[me.StaticColumn] as StaticColumn;
				ri = sc.ReportItems.Items[0];	
			}
			else
				ri = me.ColumnGroup.DynamicColumns.ReportItems.Items[0];	// dynamic column
			Rows subData = new Rows(rpt, _Data, me.FirstRow, me.LastRow, me.Rows);
			MatrixCellEntry mce = new MatrixCellEntry(subData, ri);

			return mce;
		}
示例#14
0
		MatrixCellEntry RunGetMatrixCell(Report rpt, MatrixEntry me, int iRow, Rows _Data, BitArray rows, int firstRow, int lastRow)
		{
			int headerRows = _ColumnGroupings.Items.Count;	// number of column headers we have
			int rgsCount = this.RowGroupings.StaticCount;	// count of static row groups
			int rowcell = rgsCount == 0? 0: (iRow - headerRows) % rgsCount;

			return RunGetMatrixCell(rpt, me, rowcell, me.StaticColumn, _Data, rows, firstRow, lastRow);
		}
示例#15
0
		int RunCountSubtotalRows(Report rpt, WorkClass wc, MatrixEntry m, int level)
		{
			// Get the number of static columns
			int srCount = Math.Max(1, this._RowGroupings.StaticCount);

			int count = 0;
			// Increase the row count when subtotal is requested at this level
			RowGrouping rg = (RowGrouping) (_RowGroupings.Items[level]);
			if (rg.DynamicRows != null &&
				rg.DynamicRows.Subtotal != null)
				count = srCount;

			if (m.GetSortedData(rpt) == null || level+1 >= _RowGroupings.Items.Count)		   
				return count;

			// Now dive into the data
			foreach (MatrixEntry ame in m.GetSortedData(rpt))
			{
				count += RunCountSubtotalRows(rpt, wc, ame, level+1);
			}

			return count;
		}
示例#16
0
		void HandleColumnGrouping(Report rpt, WorkClass wc, Rows rows, Row r, MatrixEntry m, int cgi, int iRow, ref int maxColumns)
		{
			while (cgi < _ColumnGroupings.Items.Count)
			{
				ColumnGrouping cg = _ColumnGroupings.Items[cgi] as ColumnGrouping;
				Grouping grp=null;
				string result;
				
				if (cg.StaticColumns != null)	// handle static columns
				{
					for (int sci=0; sci < cg.StaticColumns.Items.Count; sci++)
					{
						result = Convert.ToChar(Convert.ToInt32('a')+sci).ToString() + terminal;	// static column; put all data in it
						StaticColumn sc = cg.StaticColumns.Items[sci] as StaticColumn;
						MatrixEntry ame;
                        m.HashData.TryGetValue(result, out ame);
                        if (ame == null)
						{
							ame = new MatrixEntry(r, result, m, rows.Data.Count);
							ame.ColumnGroup = cg;
							ame.StaticColumn = sci;
							m.HashData.Add(result, ame);
							if (cg == LastCg)		// Add a column when we add data at lowest level
								maxColumns++;
						}
						ame.Rows.Set(iRow, true);
						// Logic in FirstRow and Last row determine whether value gets set
						ame.FirstRow = iRow;
						ame.LastRow = iRow;
						HandleColumnGrouping(rpt, wc, rows, r, ame, cgi+1, iRow, ref maxColumns);
					}
					break;	// handled ones below it recursively
				}
				else							// handle dynamic columns
				{
					grp = cg.DynamicColumns.Grouping;

					StringBuilder sb = new StringBuilder();
					foreach (GroupExpression ge in grp.GroupExpressions.Items)
					{
						string temp = ge.Expression.EvaluateString(rpt, r);
						if (temp == null || temp == "")
							sb.Append(nullterminal);
						else
							sb.Append(temp);
						sb.Append(terminal);		// mark end of group 
					}
					result = sb.ToString();

					MatrixEntry ame;
                    m.HashData.TryGetValue(result, out ame);
					if (ame == null)
					{
						ame = new MatrixEntry(r, result, m, rows.Data.Count);
						ame.ColumnGroup = cg;
						m.HashData.Add(result, ame);
						if (cg == LastCg)		// Add a column when we add data at lowest level
							maxColumns++;
					}
					ame.Rows.Set(iRow, true);
					// Logic in FirstRow and Last row determine whether value gets set
					ame.FirstRow = iRow;
					ame.LastRow = iRow;
					m = ame;			// now go down a level
					cgi++;
				}
			}
		}
示例#17
0
		private void SetGrouping(Report rpt, Grouping g, MatrixEntry me, Rows data)
		{
			if (g == null)
				return;

			if (me.Data == null)
				me.Data = new Rows(rpt, data, me.FirstRow, me.LastRow,  me.Rows);
			g.SetRows(rpt, me.Data);
		}
示例#18
0
		private void SetGroupingValuesMe(Report rpt, Rows data, MatrixEntry me)
		{
			if (me == null)
				return;
			// handle the column grouping
			if (me.ColumnGroup != null && me.ColumnGroup.DynamicColumns != null)
				SetGrouping(rpt, me.ColumnGroup.DynamicColumns.Grouping, me, data);

			// handle the row grouping
			if (me.RowGroup != null && me.RowGroup.DynamicRows != null)
				SetGrouping(rpt, me.RowGroup.DynamicRows.Grouping, me, data);

			if (me.Parent != null)	// go up the tree??
				SetGroupingValuesMe(rpt, data, me.Parent);
		}
示例#19
0
		private void SetGroupingValuesInit(Report rpt, Rows data, MatrixEntry rme, MatrixEntry cme)
		{
			// handle the column grouping
			if (cme != null)
			{
				foreach (ColumnGrouping cg in this.ColumnGroupings.Items)
				{
					if (cg.DynamicColumns != null)
						SetGrouping(rpt, cg.DynamicColumns.Grouping, cme, data);
				} 
			}
			// handle the row grouping
			if (rme != null)
			{
				foreach (RowGrouping rg in this.RowGroupings.Items)
				{
					if (rg.DynamicRows != null)
						SetGrouping(rpt, rg.DynamicRows.Grouping, rme, data);
				}
			}
		}
示例#20
0
		MatrixCellEntry RunGetMatrixCell(Report rpt, MatrixEntry me, int rcell, int ccell, Rows _Data, BitArray rows, int firstRow, int lastRow)
		{
			MatrixRow mr = this._MatrixRows.Items[rcell];
			MatrixCell mc = mr.MatrixCells.Items[ccell];
			ReportItem ri = mc.ReportItems.Items[0]; 
			Rows subData = new Rows(rpt, _Data, firstRow, lastRow, rows);
			MatrixCellEntry mce = new MatrixCellEntry(subData, ri);

			return mce;
		}
		public void SetME(Report rpt, MatrixEntry me)
		{
			WorkClass wc = GetWC(rpt);
			wc.ME = me;
		}
示例#22
0
		void RunColumnHeaders(Report rpt, WorkClass wc, MatrixEntry m, MatrixCellEntry[,] matrix, Rows _Data, int iRow, ref int iColumn, int level)
		{
			foreach (MatrixEntry ame in m.GetSortedData(rpt))
			{
				matrix[iRow, iColumn] = RunGetColumnHeader(rpt, ame, _Data);
				matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]);
				matrix[iRow, iColumn].Height = ame.ColumnGroup.Height == null? 0: ame.ColumnGroup.Height.Points;
				if (ame.GetSortedData(rpt) != null)
				{
					RunColumnHeaders(rpt, wc, ame, matrix, _Data, iRow+1, ref iColumn, level+1);
				}
				else
					iColumn++;
			}

			ColumnGrouping cg = (ColumnGrouping) (_ColumnGroupings.Items[level]);

			// if we need subtotal on the group
			if (cg.DynamicColumns != null &&
				cg.DynamicColumns.Subtotal != null)
			{
				ReportItem ri =  cg.DynamicColumns.Subtotal.ReportItems.Items[0];	
				matrix[iRow, iColumn] = new MatrixCellEntry(_Data, ri);
				matrix[iRow, iColumn].Height = cg.Height.Points;
				matrix[iRow, iColumn].Width = RunGetColumnWidth(matrix[iRow, iColumn]);
				RunColumnStaticHeaders(rpt, wc, matrix, _Data, iRow, iColumn, level);
				iColumn += this.CountMatrixCells;
			}
		}
示例#23
0
		// RunBuild is used by both Matrix.Run and Chart.Run to obtain the necessary data
		//   used by their respective rendering interfaces
		public MatrixCellEntry[,] RunBuild(Report rpt, out int numRows, out int numCols)
		{
			WorkClass wc = GetValue(rpt);
			Rows _Data = wc.Data;

			// loop thru all the data;
			//    form bitmap arrays for each unique data value of each grouping (row and column) value
			int maxColumns = _RowGroupings.Items.Count;	// maximum # of columns in matrix
									// at top we need a row per column grouping
			int maxRows = _ColumnGroupings.Items.Count;	// maximum # of rows in matrix
									// at left we need a column per row grouping

			MatrixEntry mcg = new MatrixEntry(null, "", null, _Data.Data.Count);
			_ColumnGroupings.SetME(rpt, mcg);
			mcg.FirstRow=0;
			mcg.LastRow=_Data.Data.Count-1;
			mcg.Rows = new BitArray(_Data.Data.Count, true);	// all data

			MatrixEntry mrg = new MatrixEntry(null, "", null, _Data.Data.Count);
			_RowGroupings.SetME(rpt, mrg);
			mrg.FirstRow=0;
			mrg.LastRow=_Data.Data.Count-1;
			mrg.Rows = new BitArray(_Data.Data.Count, true);		// all data

			int iRow=0;				// row counter
			foreach (Row r in _Data.Data)
			{
				// Handle the column values
				HandleColumnGrouping(rpt, wc, _Data, r, mcg, 0, iRow, ref maxColumns);

				// Handle the row values
				HandleRowGrouping(rpt, wc, _Data, r, mrg, 0, iRow, ref maxRows);

				iRow++;
			}

			// Determine how many subtotal columns are needed
			maxColumns += RunCountSubtotalColumns(rpt, wc, mcg, 0);

			// Determine how many subtotal rows are needed
			maxRows += RunCountSubtotalRows(rpt, wc, mrg, 0);

			/////
			// Build and populate the 2 dimensional table of MatrixCellEntry
			//    that constitute the matrix
			/////
			MatrixCellEntry[,] matrix = new MatrixCellEntry[maxRows, maxColumns];
	
			// Do the column headings
			int iColumn = _RowGroupings.Items.Count;
			RunColumnHeaders(rpt, wc, mcg, matrix, _Data, 0, ref iColumn, 0);

			// Do the row headings
			iRow = _ColumnGroupings.Items.Count;
			RunRowHeaders(rpt, wc, mrg, matrix, _Data, ref iRow, 0, 0);

			// Do the row/column data
			iRow = _ColumnGroupings.Items.Count;		
			RunDataRow(rpt, wc, mrg, mcg, matrix, _Data, ref iRow, _RowGroupings.Items.Count, 0);

			// Do the corner
			matrix[0, 0] = RunCorner(_Data);

			// now return the matrix data
			numRows = maxRows;
			numCols = maxColumns;
			return matrix;
		}
示例#24
0
		MatrixCellEntry RunGetRowHeader(Report rpt, MatrixEntry me, Rows _Data)
		{
			ReportItem ri;
			if (me.RowGroup.StaticRows != null)
			{	// Handle static row reference
				StaticRow sr = me.RowGroup.StaticRows.Items[me.StaticRow] as StaticRow;
				ri = sr.ReportItems.Items[0];	
			}
			else	// handle dynamic row reference
				ri = me.RowGroup.DynamicRows.ReportItems.Items[0];	
			Rows subData = new Rows(rpt, _Data, me.FirstRow, me.LastRow, me.Rows);
			MatrixCellEntry mce = new MatrixCellEntry(subData, ri);

			return mce;

		}