Search Results

Search found 5 results on 1 pages for 'kol'.

Page 1/1 | 1 

  • Recursion Problems in Prolog

    - by Humble_Student
    I'm having some difficulties in prolog, I'm trying to write a predicate that will return all paths between two cities, although at the moment it returns the first path it finds on an infinite loop. Not sure where I'm going wrong but I've been trying to figure this out all day and I'm getting nowhere. Any help that could be offered would be appreciated. go:- repeat, f([],0,lon,spa,OP,OD), write(OP), write(OD), fail. city(lon). city(ath). city(spa). city(kol). path(lon,1,ath). path(ath,3,spa). path(spa,2,kol). path(lon,1,kol). joined(X,Y,D):- path(X,D,Y);path(Y,D,X). f(Ci_Vi,Di,De,De,PaO,Di):- append([De],Ci_Vi,PaO), !. f(Cities_Visited,Distance,Start,Destination,Output_Path,Output_Distance):- repeat, city(X), joined(Start,X,D), not_member(X,Cities_Visited), New_Distance is Distance + D, f([Start|Cities_Visited],New_Distance,X,Destination,Output_Path,Output_Distance). not_member(X,List):- member(X,List), !, fail. not_member(X,List). The output I'm expecting here is [spa,ath,lon]4 [spa,kol,lon]3. Once again, any help would be appreciated. Many thanks in advance.

    Read the article

  • What does the English word "for" exactly mean in "for" loops?

    - by kol
    English is not my first language, but since the keywords in programming languages are English words, I usually find it easy to read source code as English sentences: if (x > 10) f(); = "If variable x is greater than 10, then call function f." while (i < 10) ++i; = "While variable i is less than 10, increase i by 1." But how a for loop is supposed to be read? for (i = 0; i < 10; ++i) f(i); = ??? I mean, I know what a for loop is and how it works. My problem is only that I don't know what the English word "for" exactly means in for loops.

    Read the article

  • How do I Insert Record MVVM through WCF

    - by DG KOL
    Hello, I’m new in MVVM Pattern (Using Galasoft MVVM Light toolkit). I’ve created a Test Project where I want to fetch some records from Database through WCF. This is working fine but I’ve failed to insert new record from View; Here is My Code: Database Table Name: TestUser (First Name, LastName) WCF (NWCustomer) Two Methods Public List<TestUser> GetAllUsers() [“LINQ2SQL Operation”] Public bool AddUser(TestUser testuser) Public bool AddUser(TestUser testuser) { try { using (DBDataContext db = new DBDataContext()) { TestUser test = new TestUser() { FirstName = testuser.FirstName, LastName = testuser.LastName }; db.TestUser.InsertOnSubmit(test); db.SubmitChanges(); } } catch (Exception ex) { return false; } return true; } Silverlight Project MODEL consists ITestUserService.cs TestUserService.cs public void AddTestTable(TestTableViewModel testuser, Action<bool> callback) { NWCustomerClient client = new NWCustomerClient("BasicHttpBinding_NWCustomer"); client.AddTestUserCompleted += (s, e) => { var userCallback = e.UserState as Action<bool>; if (userCallback == null) { return; } if (e.Error == null) { userCallback(e.Result); return; } userCallback(false); }; client.AddTestUserAsync(testuser.Model); } VIEWMODEL TestUserViewModel public TestUser User { get; private set; } public const string DirtyVisibilityPropertyName = "DirtyVisibility"; private Visibility _dirty = Visibility.Collapsed; public Visibility DirtyVisibility { get { return _dirty; } set { if (_dirty == value) { return; } _dirty = value; RaisePropertyChanged(DirtyVisibilityPropertyName); } } public TestUserViewModel (TestUser user) { User = user; user.PropertyChanged += (s, e) => { DirtyVisibility = Visibility.Visible; }; } MainViewModel public ObservableCollection<TestUserViewModel> TestTables { get; private set; } public const string ErrorMessagePropertyName = "ErrorMessage"; private string _errorMessage = string.Empty; public string ErrorMessage { get { return _errorMessage; } set { if (_errorMessage == value) { return; } _errorMessage = value; RaisePropertyChanged(ErrorMessagePropertyName); } } private ITestUserService _service; public RelayCommand< TestUserViewModel> AddTestUserRecord { get; private set; } public MainTestTableViewModel (ICustomerService service) { _service = service; TestTables = new ObservableCollection<TestTableViewModel>(); service.GetAllTestTable(HandleResult); } private void HandleResult(IEnumerable<TestTable> result, Exception ex) { TestTables.Clear(); if (ex != null) { //Error return; } if (result == null) { return; } foreach (var test in result) { var table = new TestTableViewModel(test); TestTables.Add(table); } } XAML <Grid x:Name="LayoutRoot"> <StackPanel> <TextBox Text="FirstName" /> <TextBox Text="LastName" /> <Button Content="Add Record" Command="{Binding AddTestUserRecord}" /> </StackPanel> </Grid> I want to add records into TestTable (Database Table). How do I insert record? In XAML two text box and a button control is present. Thanking you. DG

    Read the article

  • FormStartPosition.CenterParent does not work

    - by kol
    In the following code, only the second method works for me (.NET 4.0). FormStartPosition.CenterParent does not center the child form over its parent. Why? Source: this SO question using System; using System.Drawing; using System.Windows.Forms; class Program { private static Form f1; public static void Main() { f1 = new Form() { Width = 640, Height = 480 }; f1.MouseClick += f1_MouseClick; Application.Run(f1); } static void f1_MouseClick(object sender, MouseEventArgs e) { Form f2 = new Form() { Width = 400, Height = 300 }; switch (e.Button) { case MouseButtons.Left: { // 1st method f2.StartPosition = FormStartPosition.CenterParent; break; } case MouseButtons.Right: { // 2nd method f2.StartPosition = FormStartPosition.Manual; f2.Location = new Point( f1.Location.X + (f1.Width - f2.Width) / 2, f1.Location.Y + (f1.Height - f2.Height) / 2 ); break; } } f2.Show(f1); } }

    Read the article

  • Why some pictures are are crooked aftes using my function?

    - by Miko Kronn
    struct BitmapDataAccessor { private readonly byte[] data; private readonly int[] rowStarts; public readonly int Height; public readonly int Width; public BitmapDataAccessor(byte[] data, int width, int height) { this.data = data; this.Height = height; this.Width = width; rowStarts = new int[height]; for (int y = 0; y < Height; y++) rowStarts[y] = y * width; } public byte this[int x, int y, int color] // Maybe use an enum with Red = 0, Green = 1, and Blue = 2 members? { get { return data[(rowStarts[y] + x) * 3 + color]; } set { data[(rowStarts[y] + x) * 3 + color] = value; } } public byte[] Data { get { return data; } } } public static byte[, ,] Bitmap2Byte(Bitmap obraz) { int h = obraz.Height; int w = obraz.Width; byte[, ,] wynik = new byte[w, h, 3]; BitmapData bd = obraz.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); int bytes = Math.Abs(bd.Stride) * h; byte[] rgbValues = new byte[bytes]; IntPtr ptr = bd.Scan0; System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes); BitmapDataAccessor bda = new BitmapDataAccessor(rgbValues, w, h); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { wynik[j, i, 0] = bda[j, i, 2]; wynik[j, i, 1] = bda[j, i, 1]; wynik[j, i, 2] = bda[j, i, 0]; } } obraz.UnlockBits(bd); return wynik; } public static Bitmap Byte2Bitmap(byte[, ,] tablica) { if (tablica.GetLength(2) != 3) { throw new NieprawidlowyWymiarTablicyException(); } int w = tablica.GetLength(0); int h = tablica.GetLength(1); Bitmap obraz = new Bitmap(w, h, PixelFormat.Format24bppRgb); for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { Color kol = Color.FromArgb(tablica[i, j, 0], tablica[i, j, 1], tablica[i, j, 2]); obraz.SetPixel(i, j, kol); } } return obraz; } Now, if I do: private void btnLoad_Click(object sender, EventArgs e) { if (dgOpenFile.ShowDialog() == DialogResult.OK) { try { Bitmap img = new Bitmap(dgOpenFile.FileName); byte[, ,] tab = Grafika.Bitmap2Byte(img); picture.Image = Grafika.Byte2Bitmap(tab); picture.Size = img.Size; } catch (Exception ex) { MessageBox.Show(ex.Message); } } } Most of pictures are handled correctly butsome not. Example of picture that doesn't work: It produce following result (this is only fragment of picture) : Why is that?

    Read the article

1